63 040
Assignments Done
99,1%
Successfully Done
In July 2018

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.
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions