Note that there are some explanatory texts on larger screens.

plurals
  1. POCouldnt find the Error in Guess Game Class
    text
    copied!<p>Okay, this is part of the full code of a guessing game.</p> <pre><code>public static void Game(){ //Second page of game with option of continue playing when guessed close enough to answer. Scanner scan = new Scanner(System.in); GuessingGame testgame=new GuessingGame(); testgame.Generator(); int num = testgame.GetGenNum(); //Produces a random number between 1 and 100 inclusive of 1 and 100 System.out.println("Guess the target integer which is between 1 and 100 inclusive"); int guess=scan.nextInt(); int difference=(guess-num); while(guess!=num){ int yesCounter=0; System.out.println("Guess again " +num+" "+difference); guess=scan.nextInt(); difference=(guess-num); ///something wrong here, shouldnt repeat if difference too big if(difference&lt;=5||difference&gt;=-5){ //something wrong with the condition, it says its close enough even tho it isnt. while(yesCounter&lt;1){ System.out.println("Close enough, do you want to keep Guessing? Y/N "); yesCounter++; String play = scan.nextLine(); //play=play1; while(!(play.equalsIgnoreCase("y"))) { if(play.equalsIgnoreCase("n")){ System.exit(1); } else{ if((play.equalsIgnoreCase("y"))){ invalid(); guess=scan.nextInt(); } else{ Game(); ///TAKE note as it might restart the game with new random integer } } } } } } </code></pre> <p>output is:</p> <p>.........................</p> <p>Play? Y/N</p> <p>y</p> <p>Guess the target integer which is between 1 and 100 inclusive</p> <p>50</p> <p>Guess again 44 6</p> <p>44</p> <p>Close enough, do you want to keep Guessing? Y/N </p> <p>Guess the target integer which is between 1 and 100 inclusive</p> <p>..........................</p> <p>the problem is, when user guess a number, the condition is if the difference between the guess and the generated number is 5 or smaller, tell user that its close enough, and ask if user wants to continue guessing, but the condition wasn't fulfilled and yet still runs, can someone help?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload