Hi all,
Having issues with my guessing game I made. For once its not a compiling error. For some reason my loop only executes once, and it wont re-execute when the wrong number is entered. Hoping someone can help me. Here is my code:
import javax.swing.*;
public class Guessing Game
{
public static void main(String[] args)
{
String inputString;
int randomNumber = (int)(Math.random() * 100);
// gets random value betwween 0 and 100
int inputNumber;
boolean isCorrect = false;
inputString = JOptionPane.showInputDialog(null,
"Guess my number between 0 and 100");
inputNumber = Integer.parseInt(inputString);
//changed correct to isCorrect
while(isCorrect = false)
inputString = JOptionPane.showInputDialog(null,
"Guess my number between 0 and 100");
inputNumber = Integer.parseInt(inputString);
// changed => to ==
if(inputNumber == randomNumber)
{
JOptionPane.showMessageDialog(null, "Yes! Great!");
isCorrect = true;
}
//put if on one line and added <
else if(inputNumber > randomNumber)
{
JOptionPane.showMessageDialog(null,
"Too high! Try again");
}
else
{
JOptionPane.showMessageDialog(null,
"Too low! Try again.");
isCorrect = false;
}
System.exit(0);
}
}
Thanks much,
Sam