mercredi 28 octobre 2020

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,
  4. If the guess is less than the random number, print out “Too low!”
  5. If the guess is greater than the random number, print out “Too high!”
  6. Get a new guess (save it into the same variable)
  7. Print out something like “You got it!”

My code so far:

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!");
        }
      }



Aucun commentaire:

Enregistrer un commentaire