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:
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="">".... 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.>"enter>
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here