Write a C++ program named "coin.cpp" that simulates flipping a coin repeatedly and continues until three consecutive hea

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Write a C++ program named "coin.cpp" that simulates flipping a coin repeatedly and continues until three consecutive hea

Post by answerhappygod »

Write a C++ program named "coin.cpp" that simulatesflipping a coin repeatedly and continues until three consecutiveheads are tossed. At that point, your program should display thetotal number of coin flips that were made. Use rand() function tosimulate random toss of the coin. Here are a few example runs ofthe program:
Sample run 1
Head
Tail
Tail
Head
Head
Tail
Head
Tail
Head
Head
Head
It took 11 flips to get 3 consecutive heads.
Sample run 2
Tail
Head
Tail
Tail
Tail
Tail
Head
Head
Tail
Head
Tail
Head
Head
Tail
Tail
Head
Head
Head
It took 18 flips to get 3 consecutive heads.
About Random Number Generation
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply