Requirement. 1. Use the C++ library's random number generator, and include the srand statement so that the result is not the same every time you run the program. Program I/O. Input: none. Output: either Heads or Tails. Example. Heads
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
#include <iostream>
#include <ctime>
using namespace std;
//main function
int main()
{
//calling random number generator function
srand(time(0));
int input;
cout << "Enter the number of tosses to perform: ";
cin >> input; //read input
int counter=0; //initialize counter to 0
while(1) //infinite loop
{
if(counter==input) //if limit reached
break; //exit from loop
int flip = rand() % 2; //get value
if (flip == 0) //if value is 0
cout << "Heads" << endl;
else //if value is 1
cout << "Tails" << endl;
counter=counter+1; //add 1 to counter
}
return 0;
}
the program should be based on the code above, and should not use arrays.
The program should be according to the
Please refer to the algorithm highlighted.