Answer to Question #14120 in C++ for shalenee
2012-09-04T09:52:20-04:00
(Simulation : head or tail) Write c++program that simulates flipping a coin one million times and displays the number of heads and tails.
1
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 !
Learn more about our help with Assignments:
C++
Comments
Leave a comment