Is this really 50/50 chance?
I've been trying to make a coin flip simulator, the number 1 meaning heads and 2 meaning tails, but it seems to do 1 more often. Here is the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int a = 1;
while(a = 1)
{
cout << 1+(rand() %2) << endl;
cin.get();
system("cls");
}
return 0;
}
|
You must call srand() once during your program. Include <time.h> or <ctime> and add this line of code to your program:
Okay, now its acting more 50/50
Topic archived. No new replies allowed.