-1
    import java.util.Scanner;
public class GuessingGameV1
{
    public static void main(String [] args)
    {
        //
        int counter = 0;
        double randNum = 0.0;
        randNum = Math.random();
        int rand = (int)(randNum*100);

        System.out.println("Please enter your guess: ");
        int guess = in.nextInt();

        while(guess !=rand)
        {
        if((guess< rand)&&(guess>=0))
        {
             System.out.println("Your guess is too low");       

        }
        else if((guess> rand)&&(guess<=100))
        {
            System.out.println("Your guess is too high");
        }
        else if (guess<0)
        {
            System.out.println("Out of Range! Please choose a number more than 0");
        }
        else if (guess<100)
        {
            System.out.println("Out of Range! Please choose a number less than or 100");
        }
        counter++;
    }
    System.out.println("You are correct! The number was " + rand);
    System.out.println("It took you " + counter + " tries to get it!");
}
}

My program is supposed to be a guessing game. Note I am very new to Java and I have re-written my program twice and it still gives me the error! What is wrong with my program?

Basically the user should input a number and the program will spit back wether it should be higher or lower, go again until the user gets it right. After they do it tells them the number and how many times it took them to do it.

Thanks!

  • You haven't declared `in`. I assume it's supposed to be a `Scanner` object wrapping `System.in`? – JonK Oct 30 '15 at 15:14

1 Answers1

0

You havent declared variable in.

Declare it :

Scanner in = new Scanner(System.in);

Rahman
  • 3,755
  • 3
  • 26
  • 43