Question: Write a guessing program that generates a random number and allows the user to guess the number. The user will be asked to enter their
Write a guessing program that generates a random number and allows the user to guess the number. The user will be asked to enter their guess from the keyboard. If the user guesses the secret number correctly, the program will inform the user that they guessed it and the program will end. If the user guesses incorrectly, the user will be told if their guess was too high or too low and be allowed to guess again. The program will inform the user if they guessed the number correctly, and if incorrect, the number will be revealed. This program will use the rand() and srand() functions to generate the secret number. Here is the starter code:
#include
#include
#include
using namespace std;
int main()
{
unsigned seed; // Random generator seed
// Use the time function to get a "seed
// value for srand
seed = time(0);
srand(seed);
//Now generate a secret random number for your guessing game between 1 and 10
int secret_number = 1 + rand() % 10;
//Now print your secret_number to see what prints. You may add several secret numbers to see that it changes every time.
. . . FILL IN THE CODE TO COMPLETE THE GUESSING GAME AS DESCRIBED ABOVE . . .
return 0;
}
Sample Run
Welcome to My Guessing Game Try to Guess my Secret Number, You have 2 tries
Enter a guess between 1 and 10:
5
You guessed too high, try again
3
The secret number was 2.
Better Luck Next Time!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
