Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program that simulates flipping a coin multiple times. When the program starts, ask the user how many coins they want to flip.

Write a C++ program that simulates flipping a coin multiple times. When the program starts, ask the user how many coins they want to flip. Then, your program will "flip a coin" that many times. Before each coin flip, the user will guess whether the coin will show heads or tails by entering 'h' or 't'. To simulate a coin flip, your program should generate a random number to indicate whether the coin landed on heads or tails. (Hint: Think about what you want your range of possible random numbers to be. How many outcomes are possible with a coin flip?). After each flip, tell the user what side the coin landed on and if they guessed correctly or not. After the final coin flip, print out how many times the user guessed correctly. Note: no need for any input validation on this problem. Your program's output should like something like this:

How many coins should I flip? 5 Guess (h)eads or (t)ails: h Tails. Incorrect! Guess (h)eads or (t)ails: t Tails. Correct! Guess (h)eads or (t)ails: t Heads. Incorrect! Guess (h)eads or (t)ails: h Heads. Correct! Guess (h)eads or (t)ails: h Tails. Incorrect! You guessed correctly 2 times.

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

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago