Question
Implement a coin tossing game using C++ functions that works as follows: 1. In main( ), ask the user for the number of times to
Implement a coin tossing game using C++ functions that works as follows:
1. In main( ), ask the user for the number of times to play (N) then call the function play( ) (explained below) to run the game.
2.Function play( ) receives N and:
a. Ask the user to guess the next coin flip outcome (h for head, t for tail).
b. If the user enters anything else than h or t, ask her again until a valid input is entered.
c. Implement and call function flipCoin( ) to get the outcome of the next coin flip. The function randomly returns h or t.
d. If the flip coin outcome matches the users guess, give her one point. If not, subtract one point. e. After repeating this process N times, the function returns (to main) the total number of points earned by the user (it may be negative).
f. Remember to initialize the point counter to zero at the beginning of the function.
3. Once back in main( ), print the user points and ask the user whether she wishes to play again. If yes, repeat the process from 1.
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