Answered step by step
Verified Expert Solution
Link Copied!

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 1 and 10 and the user tries to guess that number.
Detailed Description:
Initialization: At the start, your program should randomly choose a number between 1 and 10. This number will remain constant until the end of a game round.
User Input: Prompt the user to enter a guess between 1 and 10. Ensure you include input validation, i.e., if a user enters a number out of range or a non-numeric 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 srand(time(0))(include 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

2. Identify issues/causes for the apparent conflict.

Answered: 1 week ago