Results 1 to 3 of 3
Thread: i can't see the mistake
- 04-28-2009, 04:56 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 27
- Rep Power
- 0
i can't see the mistake
The task that I want to accomplish is after the program executes the user is prompt if he/she want to play again. I want to do it by using a second while loop but it does not work and can't see the mistake. The last line is unfinished, so that's not it.
The way I did it and posted here ( with a little change in the Boolean variable or the string ) the program either executes repeatedly or ends after prompting the use for another game regardless of the answer.
WHAT AM I DOING WRONG ???????? PLS HELP
Java Code:import javax.swing.*; import java.util.*; public class CH05EX15_Original { static Scanner console = new Scanner (System.in); public static void main(String[] args) { String strGuess,input,cont; int num,guess,counter,diff; boolean done,oneMoreGame; guess = 0; num = (int)(Math.random()* 100); done = false; oneMoreGame = false; counter = 0; cont = "yes"; input = "exit"; oneMoreGame = false; while (!oneMoreGame) { while (!done) { strGuess = JOptionPane.showInputDialog("Enter an integer greater than or equal to 0 and" + " less than a 100"); guess = Integer.parseInt(strGuess); counter++; diff = Math.abs(num - guess); if (guess == num) { JOptionPane.showMessageDialog(null,"You guessed the correct number in " + counter + " moves","YOU WON", JOptionPane.INFORMATION_MESSAGE); done = true; // JOptionPane.showInputDialog("Would you like to play again ?\n" + // "for YES press \"OK\"\n" + "For NO type \"exit\""); } else if (guess < num) { //JOptionPane.showMessageDialog(null,"Your guess is lower than the number.\n" + // "Please guess again","SORRY",JOptionPane.INFORMATION_MESSAGE); if (diff>=50) JOptionPane.showMessageDialog(null,"Less than 50","SORRY", JOptionPane.INFORMATION_MESSAGE); else if (diff>=30) JOptionPane.showMessageDialog(null,"Less than 30","SORRY", JOptionPane.INFORMATION_MESSAGE); else if (diff>=15) JOptionPane.showMessageDialog(null,"Less than 15","SORRY", JOptionPane.INFORMATION_MESSAGE); else JOptionPane.showMessageDialog(null,"Less than 0","SORRY", JOptionPane.INFORMATION_MESSAGE); } else // JOptionPane.showMessageDialog(null,"Your guess is higher than the number.\n" + // "Please guess again","SORRY",JOptionPane.INFORMATION_MESSAGE); { if (diff>=50) JOptionPane.showMessageDialog(null,"More than 50","SORRY", JOptionPane.INFORMATION_MESSAGE); else if (diff>=30) JOptionPane.showMessageDialog(null,"More than 30","SORRY", JOptionPane.INFORMATION_MESSAGE); else if (diff>=15) JOptionPane.showMessageDialog(null,"More than 15","SORRY", JOptionPane.INFORMATION_MESSAGE); else JOptionPane.showMessageDialog(null,"More than 0","SORRY", JOptionPane.INFORMATION_MESSAGE); } } JOptionPane.showInputDialog("Would you like to play again?\n" + "If YES press \"OK\" !!!\n" + "If NO type \"exit\" !!!"); if (input.equals("exit")) oneMoreGame = true; } //moq loop } }
- 04-28-2009, 05:04 AM #2
You haven't re-set done to false after asking to play again.
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 04-28-2009, 06:30 AM #3
Member
- Join Date
- Feb 2009
- Posts
- 27
- Rep Power
- 0
Similar Threads
-
PLEASE!!!help me to find mistake
By sasha20 in forum New To JavaReplies: 1Last Post: 01-11-2008, 10:50 AM -
Newbie can't spot his mistake :(
By naxalyte in forum New To JavaReplies: 4Last Post: 11-21-2007, 07:31 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks