Question: IN C + + Declare an integer variable and initialize it to 5 0 . This variable represents the number of points each player starts
IN C
Declare an integer variable and initialize it to This variable represents the number of points each player starts the game with.
Declare an enumeration constant with the values ADD, SUBTRACT, DISPLAY, GIVEUP and EXIT in order and assign integer values to to them respectively. These five items will correspond to the menu choice you will provide the player.
Using a suitable message, ask the player for the username of the player. The name may have multiple words.
Only alphabets AZ or az numeric characters and whitespace are permitted in the username.
If the player enters any other characters in the username, you need to generate an error message and ask for the name again.
Your program must keep on asking the player to enter the name until the player enters it correctly.
Generate a suitable welcome message using the username.
Generate two seeded random integers in the range of to inclusive. These random numbers will be used to compute the sum andor the difference later. The first random integer MUST BE less than the second random integer. Using a loop of choice, keep on generating the integers until it is so
Based on the enumerated constant data of Step generate menu choice for the player. Using an integer variable, ask the player to select from the menu. See Sample Output.
Design a switchcase block with a default case, use the enumerated data constants of Step as your cases. Based on the player input of Step one of the cases will be executed.
If the player chooses to ADD the two random numbers
Using a suitable message, ask the user to guess the sum of the two random numbers.
It is very hard to guess the exact sum, so we will provide a margin of error. If the absolute difference between actual sum and guessed sum is less than we will take it as a correct guess. For example, if the randomly generated numbers are and and the user guessed it is a correct guess. If the player guessed it is also a correct guess. But if they guess it is NOT a correct guess.
Increment points by for a correct guess and provide updated points value. If the guess is correct, ask if the user wants to play another game. If the player wants to play another game, generate another set of two random numbers and restart the game.
Decrement points by for an incorrect guess and provide updated points value.
If the player chooses to SUBTRACT the two random numbers
Using a suitable message, ask the user to guess the absolute difference between the two random numbers.
It is very hard to guess the exact sum, so we will provide a margin of error. If the absolute difference between actual difference and guessed difference is less than we will take it as a correct guess. For example, if the randomly generated numbers are and and the user guessed it is a correct guess. If the player guessed it is also a correct guess. But if they guess it is NOT a correct guess.
Increment points by for a correct guess and provide updated points value. If the guess is correct, ask if the user wants to play another game. If the player wants to play another game, generate another set of two random numbers and restart the game.
Decrement points by for an incorrect guess and provide updated points value.
If the player chooses to DISPLAY the first random number.
Deduct points by as the cost for displaying the number.
You need to make sure the only the first random number gets displayed, and the player is deducted points only once for the displaying it If the user chooses to display again, provide suitable error message.
If the player chooses to GIVEUP
Display both random numbers with a suitable message.
Ask if the user wants to play another game. If the player wants to play another game, generate another set of two random numbers and restart the game.
If the player chooses to Exit, display a suitable goodbye message using the name of the player and display the final points balance.
If the player enters a wrong choice, use the default case to provide an error message and ask the player to enter again.
You must use a suitable loop of choice to allow the player to repeat Steps and ie choosing from the menu and executing the corresponding case, until the user chooses to EXIT or the points balance falls below zero becomes negative Note that the player may also choose to stop the game after making the correct guess.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
