What is wrong if guess is initialized to 0 in line 14 in Listing?
Listing
1 #include
2 #include
3 #include
// Needed for the time function 4 using namespace std;
5
6 int main()
7 {
8 // Generate a random number to be guessed
9 srand(time(0));
10 int number = rand() % 101;
11
12 cout << "Guess a magic number between 0 and 100";
13
14 int guess = −1;
15 while (guess != number)
16 {
17 // Prompt the user to guess the number
18 cout << "\nEnter your guess: ";
19 cin >> guess;
20
21 if (guess == number)
22 cout << "Yes, the number is "<< number << end⌉;
23 else if (guess > number)
24 cout << "Your guess is too high " << end⌉;
25 else
26 cout << "Your guess is too low " << end⌉;
27 } // End of loop
28
29 return 0 ;
30 }
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.