Can someone help me figure out what to do on this random number guesser?

I have a random number guesser and I am trying to figure out how to get it to print and follow the other directions. Can someone help?

The instructions:

  1. Choose a random number from 0-100
  2. Get the first guess
  3. Loop while the guess does not equal the random number,
  • If the guess is less than the random number, print out “Too low!”
  • If the guess is greater than the random number, print out “Too high!”
  • Get a new guess (save it into the same variable)
  1. Print out something like “You got it!”

My code:

Scanner user = new Scanner(System.in);
      int randoNum = 1 + (int) (Math.random()* 99);
      int guess;
      System.out.println("Guess a number from 0 to 100");
      guess = user.nextInt();
      while (guess != randoNum); 
      {
        if (guess < randoNum)
        {
          System.out.println("Too low!");
        }
        else if (guess > randoNum)
        {
          System.out.println("Too high");
        }
        else 
        {
          System.out.println("You got it!");
        }
      }

This case won’t run inside a loop where guess isn’t randoNum.

You’ll need to get a new guess from the user inside of your loop too.

1 Like

I tried this but it’s still not printing.

Scanner user = new Scanner(System.in);
      int randoNum =  (int) (Math.random()* 99) + 1;
      int guess;
      System.out.println("Guess a number from 0 to 100");
      guess = user.nextInt();
      while (guess != randoNum); 
      {
        if (guess < randoNum)
        {
          System.out.println("Too low!");
        }
        else if (guess > randoNum)
        {
          System.out.println("Too high");
        }
        else 
        {
          System.out.println("You got it!");
        }
        guess = user.nextInt();
      }

See my comment above. This code cannot ever run.

How do I take the else out of the loop?

Does it need to be in an else?

I guess not. I’m not sure.