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:


1) The user guesses at a random number between 1 and 20 instead of a number between 0 and the value stored in the variable RAND_MAX


2) After the user guesses at the number, if they guess incorrectly, not only notify them that they guessed incorrectly, but also if their guess was too high or too low and then shows the magic number.





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<"enter your="" guess";="" cin="">> guess; cout<" **="" right!!="" **";="" else="" cout=""><".... sorry - you guessed incorrectly"; return 0; } modify the program so that: 1) the user guesses at a random number between 1 and 20 instead of a number between 0 and the value stored in the variable rand_max 2) after the user guesses at the number, if they guess incorrectly, not only notify them that they guessed incorrectly, but also if their guess was too high or too low and then shows the magic number. sorry="" -="" you="" guessed="" incorrectly";="" return="" 0;="" }="" modify="" the="" program="" so="" that:="" 1)="" the="" user="" guesses="" at="" a="" random="" number="" between="" 1="" and="" 20="" instead="" of="" a="" number="" between="" 0="" and="" the="" value="" stored="" in="" the="" variable="" rand_max="" 2)="" after="" the="" user="" guesses="" at="" the="" number,="" if="" they="" guess="" incorrectly,="" not="" only="" notify="" them="" that="" they="" guessed="" incorrectly,="" but="" also="" if="" their="" guess="" was="" too="" high="" or="" too="" low="" and="" then="" shows="" the="" magic="">

Answered 1 days AfterMar 10, 2021

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

Arun Shankar answered on Mar 11 2021
136 Votes
#include
#include
#include
#include
using namespace std;
int main()
{
int magic, guess;
unsigned int seed;
seed = time(NULL);
srand(seed);
magic = 1 + (rand() % 20);
cout<<"Enter your guess: ";
cin>> guess;
if (guess ==...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here