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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started