I'm making a specific number guessing game called "Bagels". I have most of the work done. But once I get to the actual game, I can only input one number for it to say if it is right or not. I need the program to keep allowing numbers to be inputted until it satisfies the do/while statement.
The input statements for the guessing are in the second do/while statement towards the bottom.
public static void main(String[] args) {
BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
System.out.println("Welcome to Bagels the Guessing Game!");
System.out.println("Press [Enter] to continue");
String rulesornot = new String ();
System.out.println("To learn the rules, enter(1)");
System.out.println(" ");
System.out.println("To skip to the game, enter(2)");
if (rules == 1) {
System.out.println("Rules: You are to guess a 3-digit number and you may not repeat a digit within an answer.");
System.out.println("If you guess correct on one number and it is in the correct spot that is \"Fermi\".");
System.out.println("If you guess correct on one number but it is not in the correct spot that is \"Pico\".");
System.out.println("If you don't guess any numbers correctly, than you will receive \"BAGELS\".");
System.out.println("Press [Enter] to continue");
String start2 = new String();// User has to press enter to continue to the game
try {start2 = input.readLine();}
catch (IOException e) {};
System.out.println("Begin guessing...");
}
else if((rules == 2) || (rules == 3))
System.out.println("Begin guessing...");
Random r = new Random();
int num;
int d1;
int d2;
int d3;
do{//generates a unique random 3 digit number
num = r.nextInt(900) + 100;
d3 = num % 10;
d2 = ((num - d3) / 10) % 10;
d1 = (num - d3 -(d2 * 10)) / 100;
Your while loop continues whilst the guess is equal to the hidden number, shouldn't this be whilst it isn't equal to the hidden number. You may want to think of adding a way to allow the user to exit from the game without having to guess the correct number.
Also you input the guess number but then don't do anything with it (other than in the while statement), shouldn't you be breaking into 3 separate digits to compare with the hidden number.
how do I make sure the game says the right stuff to the right inputted numbers?
Is it printing the "wrong" stuff now?
Try debugging your program by printing out the values of all your variables so you can see how they are set and changed by the program.
For example:
System.out.println("d1=" + d1 + ", d2=" .... for the rest of the variables
Please copy the screen contents when you run the program and paste it here and add comments to it to explain what is wrong.
Bookmarks