Question: Topic: Sentinel, Nested loops ( Chapter 5 ) , if / else ( Chapter 4 ) , random numbers ( Chapter 3 ) Do not
Topic: Sentinel, Nested loops Chapter ifelse Chapter random numbers Chapter
Do not use anything beyond chapter
Write a C program that implements a simple number guessing game with multiple questions answers. For each game, the program generates a random number between and User enters an answer with a numeric input. If the user input number matches the generated number, then print a message to inform users that heshe has a correct guess. If the guess is not correct, allow the user to have two more chances to guess the correct number.
At any time, if users enter then the program should display the game session summary and exits.
The program should keep track of the wins and losses and print the summary counts when the user chooses to exit by entering
The program should generate a new random number only after the user enters the correct guess or after the user has tried times and did not have the right guess. Do not ask the user for a yesno confirmation after each game because the input value will serve as the sentinel Chapter topic to stop the continuous game.
Here is a sample run using the command line.
At the program start, it shows:
Welcome to the number guessing game.
For each game, you have at most chances to guess a secret number from to
The first time, when a new question is asked, the program displays:
Enter a number from to Enter to exit:
When users give a wrong guess, it shows:
Not correct, try again:
When users give a wrong answer after the third trial for the same question, the program displays:
Not correct. You have reached your third trial. The correct number is X
Lets start a new game
When users answer with the correct number, it shows this prompt:
Congratulations correct! Lets start a new game.
When users hit the game summary is displayed:
Game summary:
Total games:
Total game wins:
Total game losses:
Notes:
Use the function rand to generate random numbers.
Also use time and use the srand to generate a random seed for the random generator. The srand should be called only once outside the loop before the game starts.
In main you can use a while or do loop that gets inputs.
To control the number of maximum trial answers per question, you should use a nested loop inside the main while loop. Using nested loops is fine.
Feel free to use boolean flag variables to control the loops.
Feel free to use logical expression && in Chapter
Generate a new random number only when a new game starts after users either have entered the correct answer or users have exceeded the trials.
For the count of losses, update the count only when users have exceeded the maximum trials. Do not count as a loss if users have not finished the trials.
If you use "break" "continue" inside loop, there will be deduction of points
Add Comment at the top of your program:
Author:
Description:
You can download a zip file that contains sample game by clicking here
How to run the game:
Unzip the file and save to a folder c:temp on a Windows PC Game executable file does not work on Mac.
Open the Windows command line tool from the Start menu RunType command cd to change to the directory temp
cd temp
Check that your file is in the directory by using the dir command
Welcome to the number guessing game!
For each game, you have at most chances to guess a secret number from to
Enter a number from to Enter to exit:
Congratulation, correct! Let's start a new game.
Enter a number from to Enter to exit:
Not correct, try again:
Congratulation, correct! Let's start a new game.
Enter a number from to Enter to exit:
Not correct, try again:
Not correct, try again:
Not correct. You have reached your trials. The correct number is
Lets start a new game.
Enter a number from to Enter to exit:
Here is your game summary:
Total games:
Total wins: quad
Total losses:
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
