CS 231 A-Computer Progr. -CS231-Programming-L × O wildcat cook an eduncscsfs/CS2
ID: 3590346 • Letter: C
Question
CS 231 A-Computer Progr. -CS231-Programming-L × O wildcat cook an eduncscsfs/CS23 1 Programming-I FALL-2017 Lecture 15.pdf target-b112d . 0 JAVA Bonus HW Write programs to: 1- Number guessing game. The program will pick a random number (See class Random) and ask the user to guess that number. The program output 'Too low' or Too high' based on the guess being less than or more than the number. Once the correct guess is entered, the program will print a success message along with the number of iterations the user needed to guess the number. Additionally, The user is to be informed of the range of possible values the program draws from, e.g: 1-20, or 1-100.Explanation / Answer
The error you are getting becaue you have not defined
"count" anywhere in your program.
Define count in the upper part of your program (say near scanner definition).
initialize count = 0; after int number = random.nextInt()
before entering the do while loop add count++;
Modify guess = scanner.nextInt() in the do while loop as follows:
if (guess != number){
guess = scanner.nextInt();
count++
}
Rest of all is fine.