C++ Birthday paradox equation returning 0 for all but the first one
I'm new to C++ programming and have to make a loop for calculating the
probability that two people in the same room have the same birthday. I
know the equation and just don't seem why it's coming up with zero for 3 -
50 people. :/
double chance, base, power, num(2.0);
const double constant(364.0/365.0);
int people(2);
for (int i = 0; i < 49; i++,num++,people++)
{
base = (1.0 - constant);
power = (num * (num - 1.0) / 2.0);
chance = pow(base, power);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "For " << people << " people, "
<< "the probability of two birthdays is about "
<< chance * 100.0 << "%.\n";
}
Any help would be really appreciated.
No comments:
Post a Comment