The question is : Write a C++ program to play a simple number guessing game against a computer opponent. The rules of the games are as follows:
- The computer randomly selects a secret number between 0 and 100.
- The user enters a number between 0 and 100 as their secret number.
- The computer will then attempt to guess the user's number. This guessed number should be printed to the screen and if it is less than the user's secret number, the program should print, "The guess is too low"; if the guess is greater than the user's secret number, it should print "The guess is too high".
- The user will then attempt to guess the computer's secret number. This guessed number should be printed to the screen and if it is less than the computer's secret number, it should print "The guess is too low"; if the guess is above the user's secret number, it should print "The guess is too high".
- Repeat steps 3 and 4 until either the computer or the user correctly guesses the other's secret number.
- When one of the players guesses the other's number correctly, our program should state if the computer or the user won, and then our program should exit. Write a program that repeats round until the player decides to quit.
Write a C++ program to play a simple number guessing game against a computer opponent. The rules of the games are as follows:
- The computer randomly selects a secret number between 0 and 100.
- The user enters a number between 0 and 100 as their secret number.
- The computer will then attempt to guess the user's number. This guessed number should be printed to the screen and if it is less than the user's secret number, the program should print, "The guess is too low"; if the guess is greater than the user's secret number, it should print "The guess is too high".
- The user will then attempt to guess the computer's secret number. This guessed number should be printed to the screen and if it is less than the computer's secret number, it should print "The guess is too low"; if the guess is above the user's secret number, it should print "The guess is too high".
- Repeat steps 3 and 4 until either the computer or the user correctly guesses the other's secret number.
- When one of the players guesses the other's number correctly, our program should state if the computer or the user won, and then our program should exit. Write a program that repeats round until the player decides to quit.
FollowingHere is the code written by me for above question. I have tried it with different inputs and it gives the correct output :-