Alright guys so I am writing this program so that the computer creates a number and the user has to guess it by just high and low as a hint. It also has to keep track of the number of tries and output them in a JOptionPane, actually everything has to be a JOP. I have an error on my while statement hopefully I have given you all enough info to figure this out.
import java.math.*; import java.util.Random; import java.util.Scanner; import javax.swing.*; public class GuessingGame { /** * @Alec Chamberlain * @Version 1.0 * @Date:9/1/2011 * Program plays a game where you have to guess the number */ public static void main(String[] args){ // Variables String guess; int secretnum; int counter = 0; secretnum = (int) (Math.random()*1000+1); int thereguess = Integer.parseInt(guess); //Feel free to delete this. This is here so that you can have the number for testing System.out.println("Secret number is "+ secretnum); //Loop in order to being checking input against do { guess = JOptionPane.showInputDialog(null, "Please enter your number to guess:"); counter++; if (thereguess == secretnum){ counter++; JOptionPane.showMessageDialog(null, "Your guess is correct congrats it only took you:"+ counter+ " tries"); break; } else if (thereguess < secretnum){ counter++; JOptionPane.showMessageDialog(null, "Your guess is to low try again"+ counter+ " tries"); } else if (thereguess > secretnum){ counter++; JOptionPane.showMessageDialog(null, "Your guess is to high try again"+ counter+ " tries"); } else if(thereguess< 0){ counter++; JOptionPane.showMessageDialog(null, "Good Job I Win-Thanks for playing. It took you:"+ counter+ " tries"); System.exit(0); } } while(guess != secretnum); } }