Hello, I'm new here. ^^ I hope I can get something out of registering here haha
Ok, so, in our Java Programming class, we're writing a program that randomly generates a number between 1 and 100, and the user must guess what that number is. The program so far works, and it gives hints like "Too high" or "too low" and it counts the number of tries taken to reach the correct number, which is displayed in a message that says they guessed correctly.
Well, now we have to add a few features to the program so it does these 3 things:
1) When the user enters a number that is not between 1 and 100, it will give an error message and not count that guess in the number of tries to guess the correct number, and they can enter a valid number after the error message is displayed.
2) After the game is over, the user should have the option to play again. It should say something along the lines of "Play again? (Y or N)" and if the user answers with 'Y', the game should restart and if the user answers with a 'N', the loop should end.
3) If the user chooses to replay the game, the guess counter should reset back to 0.
I'm just not exactly sure how to get those above standards...
Here is the code:
Any help is greatly appreciated! ^^
public class GuessingGame2
public static void main (String args)
Random generator = new Random();
int tries = 0;
num = generator.nextInt(100) + 1;
System.out.println("Welcome to the Guessing Game!!");
System.out.print("Please enter a number between 1 and 100: ");
guess = Keyboard.readInt();
System.out.println("Too high. Try again.");
System.out.println("Too low. Try again.");
System.out.println("Correct! It took you " + tries + " tries to guess the number!");