Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program named coin.cpp that simulates a coin flipping a coin repeatedly and continues until three consecutive heads are tossed. At that point,

Write a C++ program named "coin.cpp" that simulates a coin flipping a coin repeatedly and continues until three consecutive heads are tossed. At that point, your program should display the total of coin flips that were made. Use rand() function to simulate random toss of the coin. Include: #include and #include and srand(time(0));
image text in transcribed
21:31 Write a C++ program named "coin.cpp" that simulates flipping a coin repeatedly and continues until three consecutive heads are tossed. At that point, your program should display the total number of coin tips that were made. Use and function to simulate random as of the Here are a few example runs of the program: Sample run Head Tail Head Head It took 11 flips to get ) consecutive heads. Sample run 2 Tail Tail Head Head It took 18 flips to get 3 consecutive heads. About Random Number Generation How to generate random numbers in C The function and produces a random integer number in the range between and RAND MAX (a constant defined to be the largest inteper value. The function is defined in cstdlib header file, so include it in your program: Hinelude cestdlib> How to make your program generate a different random sequence of toss each time you the program? The function and generates pesadorandion numbers based on a seed wala If we provide a different seed value cach time we ran the program, then the sequence of random values generated on each run will be different. To do this, we are going to supply the seed value as the result of the function call time ". The function call returns the number of seconds clapsed since Jan Ist, 1970. This number is going to be different cach time we run the program, therefore a good random sood value to use. The function s defined in a special header file, so include it in your programas: #include cetime To tell the program to use timer) value of the seed, we supply this value as the parameter of the function stand. (seeding for random number generator, like this srand(time()); It is important that we put this line as the first statement in the main function, night atter the local variable declarations What to Submit for this lab: For this lab, you need to submit the film.com

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

Step: 3

blur-text-image

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

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions