Write a C++ program that simulates flipping a coin (random numbers) 1000 times and displays the number of heads and tails. Note that there is no input to the program and the number of heads and tails will be around 500.
#include <iostream>
using namespace std;
int main() {
srand(time(NULL));
int heads = 0, tails = 0;
for(int i=0; i<1000; i++)
{
if(rand() % 2 == 0)
heads++;
else
tails++;
}
cout << "Heads = " << heads << endl;
cout << "Tails = " << tails << endl;
}
// Please up vote
Get Answers For Free
Most questions answered within 1 hours.