The following program for a user to guess at a random number was discussed in class:
#include
using namespace std;
int main()
{
int magic;
int guess;
unsigned int seed;
seed=time(NULL);
srand(seed);
magic=rand();
cout
cin>> guess;
if (guess == magic)
else
return 0;
}
Modify the program so that:
Modify the magic number program so that the user can guess at more than one magic number where the magic number is an integer between 1 and 20. When the program is run, the user should be prompted if they would like to guess at a magic number and continue to be prompted as such after they have guessed a magic number correctly. A while loop is necessary for this capability, The user should be given as many guesses as necessary for each number until they guess the number correctly.
A do-while loop must be implemented for this part of the program. They should also be responded with a clue after each guess on whether the guess is too high or low. The program should also make sure that if the user enters an invalid guess at the magic number (less than 1 or greater than 20), then the user should be prompted with an invalid guess message and not be penalized for a guess attempt. A while loop must be implemented for this part of the program. After the user guesses the number correctly, they should be graded on their effort. If they guess the number correctly within 3 guesses, rate them as "Excellent". If they guess the number correctly within 5 guesses, rate them as "Good". If they guess the number correctly within 7 guesses, rate them as "Average". If they guess the number correctly with more than 7 guesses, rate them as "Poor". Use either an if-else-if ladder or a switch block to rate the user.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here