Answer to Question #14120 in C++ for shalenee

Question #14120
(Simulation : head or tail) Write c++program that simulates flipping a coin one million times and displays the number of heads and tails.
1
Expert's answer
2012-09-06T09:26:39-0400
#include <iostream>
#include <stdlib.h>
using namespace std;

int main () {
srand(0);
int headCount = 0;
for (int i = 0 ; i < 1000000 ; i++){
& bool head = rand()%2;
& if (head == true) headCount++;
}
cout<< "head = " << headCount << " tail = "<< 1000000 - headCount<<endl;
system("pause");
return 0;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS