My do while loop is not entering the while loop

Viewed 19

I'm trying to complete my homework assignment and am having trouble. The instructions state that I need to change the while expression to a not but whenever I do it wont enter the loop.

import java.util.Scanner;

public class GuessNumberApp {

public static void main(String[] args) {
    final int LIMIT = 10;

    System.out.println("Guess the number!");
    System.out.println("I'm thinking of a number from 1 to " + LIMIT);
    System.out.println();

    // get a random number between 1 and the limit
    double d = Math.random() * LIMIT; // d is >= 0.0 and < limit
    int number = (int) d;             // convert double to int
    number++;                         // int is >= 1 and <= limit

    Scanner sc = new Scanner(System.in);            
    int count = 1;
    int guess;
    do {
        System.out.print("Your guess: ");
        guess = Integer.parseInt(sc.nextLine());
    }
        while (guess != number); {
            if (guess < 1 || guess > LIMIT) {
                System.out.println("Invalid guess. Try again.");
            }
            else if (guess < number) {
                System.out.println("Too low.");
                count++;
            } 
            else if (guess > number) {
                System.out.println("Too high.");
                count++;
            }
        }
    System.out.println("You guessed it in " + count + " tries.\n");
    System.out.println("Bye!");
}   

}

0 Answers
Related