Number guessing Game  Write a C program that implements the “guess my number” game. The computer chooses a random number using the following random generator function srand(time(NULL)); int r = rand() % 100 + 1; that creates a random number between 1 and 100 and puts it in the variable r. (Note that you have to include ) Then it asks the user to make a guess. Each time the user makes a guess, the program tells the user if the entered number is larger or smaller than its number. The user then keeps guessing till he/she finds the number. If the user doesn’t find the number after 10 guesses, a proper game over message will be shown and the actual guess is revealed. If the user makes a correct guess in its allowed 10 guesses, then a proper message will be shown and the number of guesses the user made to get the correct answer is also printed. After each correct guess or game over, the user decides to play again or quit and based on the user choice, the computer will make another guess and goes on or prints a proper goodbye message and quits A sample run is as follows (user inputs are in red): Welcome to the Number Guess Game! I choose a number between 1 and 100 and you have only 10 chanced to guess it! OK, I made my mind! What is your guess? > 5 My number is larger than 5! 9 guesses left. What is your guess? > 75 My number is smaller than 75! 8 guesses left. What is your guess? > 40 My number is smaller than 40! 7 guesses left. What is your guess? > 23 My number is larger than 23! 6 guesses left. What is your guess? > 30 My number is larger than 30! 5 guesses left. What is your guess? > 35 You did it! My number is 35! You found it with just 6 guesses. Do you want to play again? (Y/N) > Y OK, I made my mind! What is your guess? > 15 My number is larger than 15! 9 guesses left. … And if the user makes 10 guesses without a success … What is your guess? > 405 Please enter a number between 1 and 100 What is your guess? > 45 My number is larger than 45! 1 guess left. What is your guess? > 47 SORRY! You couldn’t find it with 10 guesses! My number was 46. Maybe next time! Do you want to play again? (Y/N) > N Thanks for playing! See you later.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section: Chapter Questions
Problem 7PP
icon
Related questions
Question
  1. Number guessing Game 

Write a C program that implements the “guess my number” game. The computer chooses a random number using the following random generator function

srand(time(NULL));

int r = rand() % 100 + 1;

that creates a random number between 1 and 100 and puts it in the variable r. (Note that you have to include <time.h>) Then it asks the user to make a guess. Each time the user makes a guess, the program tells the user if the entered number is larger or smaller than its number. The user then keeps guessing till he/she finds the number.

If the user doesn’t find the number after 10 guesses, a proper game over message will be shown and the actual guess is revealed. If the user makes a correct guess in its allowed 10 guesses, then a proper message will be shown and the number of guesses the user made to get the correct answer is also printed.

After each correct guess or game over, the user decides to play again or quit and based on the user choice, the computer will make another guess and goes on or prints a proper goodbye message and quits A sample run is as follows (user inputs are in red):

Welcome to the Number Guess Game!
I choose a number between 1 and 100 and you have only 10 chanced to guess it!

OK, I made my mind!

What is your guess? > 5

My number is larger than 5!

9 guesses left.

What is your guess? > 75

My number is smaller than 75!

8 guesses left.

What is your guess? > 40

My number is smaller than 40!

7 guesses left.

What is your guess? > 23

My number is larger than 23!

6 guesses left.

What is your guess? > 30

My number is larger than 30!

5 guesses left.

What is your guess? > 35

You did it! My number is 35!
You found it with just 6 guesses.

Do you want to play again? (Y/N) > Y

OK, I made my mind!

What is your guess? > 15

My number is larger than 15!

9 guesses left.

And if the user makes 10 guesses without a success

What is your guess? > 405

Please enter a number between 1 and 100

What is your guess? > 45

My number is larger than 45!

1 guess left.

What is your guess? > 47

SORRY! You couldn’t find it with 10 guesses!

My number was 46. Maybe next time!

Do you want to play again? (Y/N) > N

Thanks for playing! See you later.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning