Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Objective: Develop a simple game where the computer selects a random number between 1 and 1 0 and the user tries to guess that number.
Objective: Develop a simple game where the computer selects a random number between and and the user tries to guess that number.
Detailed Description:
Initialization: At the start, your program should randomly choose a number between and This number will remain constant until the end of a game round.
User Input: Prompt the user to enter a guess between and Ensure you include input validation, ie if a user enters a number out of range or a nonnumeric value, prompt them again to enter a valid guess.
Feedback to User: After the user makes a guess:
If the guess is correct, congratulate the user and let them know they've guessed the number correctly.
If the guess is too high, inform the user that their guess is too high and prompt them to try again.
If the guess is too low, inform the user that their guess is too low and prompt them to try again.
Ending the Game: Once the user has guessed the correct number, the game should end. Optionally, you can ask the user if they would like to play again.
Bonus: Keep track of the number of attempts it took the user to correctly guess the number and display it at the end of each round.
Hints:
Consider using the rand function from the cstdlib library to generate random numbers.
Remember to seed your random number generator with srandtimeinclude the ctime library for this at the beginning of the main function. This ensures you get a different random number every time you run the program.
Expected Output:
Your game, when run, might look something like this:
image.png
Submission: Please submit your source code file and a brief report on any challenges you faced and how you overcame them.
You can choose to use this code to get you started:
starting code.png
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