I will post both the project and code below... I have two questions. When the user enters O to quit why can I not get my response to display? When I enter 0 the program just quits but I want it to display "Thanks for playing. Good Bye" Also, should I be able to enter a number higher than 100 if it is only suppose to be 1- 100 inclusive? if I enter 101 or 102 it still will tell me if the number is too high. My code compiles and runs except for these two problems. Thank you for your help.
Design and implement an application that plays a guessing game with numbers. The program should generate a random number between 1 and 100 (inclusive), then repeatedly prompt the user to guess the number. On each guess, display a message to the user indicating their guess is correct or the guess is too high or too low. Continue accepting guesses until the user guesses correctly or chooses to quit. Accept a sentinel value (0 is often used) to allow the user to signal they want to quit. Keep a count the number of guesses and report the count when the user guesses correctly. At the end of each game (by quitting or a correct guess), prompt the user to indicate whether they want to play again. Continue playing games until the user chooses to stop.import java.util.Scanner; import java.util.Random; public class GuessingGame { public static void main (String[] args) { final int MAX = (100); int guess, number; java.util.Scanner scan = new java.util.Scanner(System.in); System.out.print (" Can you guess the number I am thinking of?" + " Guess what it is between 1 and 100(or 0 to quit) "); //Random generator 1-100 guess = scan.nextInt(); Random generator = new Random(); number = generator.nextInt(MAX)+1; //If statement if (guess == number) { System.out.println (" Great guess!! You got it right!! "); } //if user enters 0 else if (number == 0) { System.out.println (" Thanks for playing. Good bye. "); } // guess is not 0 or number while (guess != number && guess != 0) { //guess is higher than number if (guess > number && guess != 0) { System.out.println (" Your guess is too high! "); guess = scan.nextInt(); } else { // guess is lower thsn number if (guess < number && guess !=0) { System.out.println (" Your guess is too low!"); guess = scan.nextInt(); } //guess is equal to number else if ( guess == number) { System.out.println(" Great guess!! You got it right!! "); } //game ends else if (guess == 0) { System.out.println (" Thanks for playing. Good bye. "); } } } if (guess == number) { System.out.println(" Great guess!! You got it right! "); } } }