Question: 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

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!