Question: Homework 3 : Coin Game Filename: coingame.cpp This program will play a game with the user. The goal of the game is to use different

Homework 3: Coin Game
Filename: coingame.cpp
This program will play a game with the user. The goal of the game is to use different numbers of US Coins to match a dollar amount that the user specifies. The user wins if they can give you a correct breakdown of an amount of half dollars, quarters, dimes, nickels, and pennies that adds up to whatever amount they specify.
Write a program that does the following:
Welcome the user to the game. This should be done only once, at the beginning of the program.
Then, enter into a LOOP, that does the following, in order:
Present the user with the following menu:
p - play
s - stats
q - quit
choice:
Allow the user to enter a menu entry.
Your program should accept both UPPER and LOWER case letters as valid menu entries. Ex: 'P' and 'p' should both play the game.
Now, DETERMINE what selection the user made. The selection options are either P S Q or some Invalid Option:
PLAY:
Prompt them for a dollar amount (as a double) that they will attempt to match with their coin entries.
DO NOT LET THE USER PROCEED if they enter a negative target amount. You can use a loop here to Force the user to retry should they make a bad entry (see sample run 3).
Now, allow the user to enter an integer amount for the number of half dollars, quarters, dimes, nickels, and pennies that they'd like.
If any of the values they enter for the number of each coin is negative, display an error message and count that game as a loss. Otherwise, check to see if the user won the game. Add up the total amount of $ they entered and compare it against the value they entered when the program began.
If the amount matches the target amount, they won! Print out: "YOU WIN!" and count the game as a win. If they lost, print out "YOU LOST by: " and then the amount of $ that they were off by, and count the game as a loss.
STATS:
Print the number of wins and losses to the screen as seen in the sample runs.
QUIT:
Print out the final statistics which include the wins, losses, and the Final Win Percentage.
The final win percentage must be printed to 2 decimal places.
If the user quits the game without having played any games, print the "guess you're scared" messaged seen in sample run 5
SOMETHING ELSE OTHER THAN PLAY, STATS, or QUIT:
If the user enters an invalid character that is not on the menu, your program should print an error message as seen in the sample run 2.
Your overall loop should now conclude, and should restart if the user selected anything other than the quit option.
Hints
As you go through the program, you will have to keep track of the number of wins and losses. Don't forget to begin the variables representing these counts at 0 at the beginning of your program.
Remember integer math and what that can do, especially when performing division!
a "do - while" loop is ideal here, in my opinion, for the overall looping of the program. This is because we are performing a pattern of: show menu to user, gather user's value, determine value, and then *check to see if we do this all over again*. Since this *check* is at the END of this pattern, a do-while fits naturally here. You can though use any kind of loops you'd like. I would NOT recommend using for loops in this program.
Your program will NEED to utilize at least 2 loops, the previously mentioned one which loops the menu/gameplay, as well as one during gameplay which forces the user to retry should they enter a negative target amount.
Rules
If the user loses the game, the difference (amount they were off by) should never display as a negative value.
Don't allow your program to divide by 0. This can happen when the user quits without having played any games.
When error checking you DO NOT need to account for the user entering a different data type than the one expected. For example you do not need to worry about the user entering a character when entering the target amount to match when playing the game.
All dollar values printed must be printed in dollar format $dd.cc (to two decimal places).
You may ONLY HAVE ONE return statement which is the last line of main() in each of your mini-programs. No exit statements are permitted, either.
Declare ALL of your variables at the beginning of main(), not scattered throughout.

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!