Question: Rather than display heads or tails have the function return an int - either 0 or 1 - and let the main program handle the

Rather than display "heads" or "tails" have the function return an int - either 0 or 1 - and let the main program handle the output. In addition, after the user enters the total number of tosses, after displaying the sequence of heads and tails also state the total number of heads and total number of tails obtained. C++

This is what i have so far.

#include

#include

#include

using namespace std;

void coinTossed();

int main()

{

int number;

unsigned seed=time(0);

srand(seed);

cout<<"Please enter the numbe of time you want to toss the coin ";

cin>>number;

for(int i=1; i<=number;i++)

{

coinTossed();

}

return 0;

}

void coinTossed()

{

int y;

const int MIN_VALUE=1;

const int MAX_VALUE=2;

y=(rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE;

if (y==1)

cout<<"Heads ";

else

cout<<"Tails ";

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!