似乎无法让它发挥作用。这个想法是在每次计数后计算正面和反面的百分比,在每次迭代后累积。除了我的计算不断得到nan%。有人看到我做错了什么吗?
void flipCoin(time_t seconds, int flipCount){
vector<int> flips;
float headCount = 0;
float tailCount = 0;
double headProbability = double((headCount/(headCount + tailCount))*100);
double tailProbability = double((tailCount/(headCount + tailCount))*100);
for (int i=0; i < flipCount; i++) {
int flip = rand() % (HEADS - TAILS + 1) + TAILS;
flips.push_back(flip);
if (flips[i] == 1) {
tailCount++;
cout << "Tail Percent: " << tailProbability << "%" << endl;
}else{
headCount++;
cout << "Head Percent: " << headProbability << "%" << endl;
}
}
}