Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions