The following program for a user to guess at a random number was discussed in class: #include #include #include #include using namespace std; int main() { int magic; int guess; unsigned int seed;...

1 answer below »

The following program for a user to guess at a random number was discussed in class:


#include


#include


#include


#include


using namespace std;


int main()


{


int magic;


int guess;


unsigned int seed;


seed=time(NULL);


srand(seed);


magic=rand();


cout


cin>> guess;


cout


if (guess == magic)



cout



else



cout


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.





Answered Same DayApr 14, 2021

Answer To: The following program for a user to guess at a random number was discussed in class: #include...

Kshitij answered on Apr 14 2021
139 Votes
# include
# include
# include
# include
using namespa
ce std;
int main() {
int magic;
int guess;
srand(time(0));
bool result = false;
int c = 0;
while (result == false) {
int magic = (rand() % 20) + 1;
cout << "Enter the...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here