Problem

What is wrong if guess is initialized to 0 in line 14 in Listing?Listing1 #include 2 #incl...

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;

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 }

Step-by-Step Solution

Request Professional Solution

Request Solution!

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.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT