-2

I think I am missing brackets somewhere but I have been searching for 3 hours and cannot find what is wrong, nor has googling helped me at all.

I tried adding end braces/brackets to the if then statements but then I get a bunch of errors. Probably is going to be a "duh" moment once someone finds out what I did.. Thanks in advance.

ERRORS: NumberGame.java:45: error: reached end of file while parsing } ^ NumberGame.java:51: error: reached end of file while parsing 2 errors

import java.util.*;

public class NumberGame
{
    public static void main(String[] args)
    {
        double R = 0;
        double tryit = 0;
        double a = 0;
        double b = 0;
        while (tryit == 0)
        {
            R = 0;
            while (R != 1)
            {
                a = (int)(Math.Random() * 10);
                b = (int)(Math.Random() * 10);
                if (a -b >= 0){
                    R = 1;
            }
        }
        double inpt = -7;
            while (inpt != (a-b))
            {
                Sytem.out.println("What is " + a + " minus " + b + " ? ");

                inpt = scanner.inpt = new Scanner(System.in);

                if ((a -b) == inpt){
                    System.out.print("Good job, you are correct");
                    System.out.println("Play again?, Yes or No?:");
                    String inpt2 = scanner.inpt2 = new Scanner(System.in);
                if ((a-b) != inpt){
                    System.out.println("Sorry try again");

            }
        if (inpt2 == "No"){
            System.out.println("Thanks for playing");
            break;
        if (inpt2 == "no"){
            System.out.println("Thanks for playing");
            break;
    }
}
Martelmungo
  • 42
  • 1
  • 8

3 Answers3

2

Every if statement has an opening brace, but not a closing one.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Neil Smithline
  • 1,526
  • 9
  • 21
1

Your if statements need closing brackets.

    if (a -b >= 0){
        R = 1;
    } // Closing bracket

    ....

    if ((a -b) == inpt) {
        System.out.print("Good job, you are correct");
        System.out.println("Play again?, Yes or No?:");
        String inpt2 = scanner.inpt2 = new Scanner(System.in);
    } // Closing bracket
    if ((a-b) != inpt){
        System.out.println("Sorry try again");
    } // Closing bracket

    ...

    // I think you only need one of these and not two
    if (inpt2 == "No"){
        System.out.println("Thanks for playing");
        break;
    } // Closing bracket
    if (inpt2 == "no"){
        System.out.println("Thanks for playing");
        break;
    } // Closing bracket
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Shar1er80
  • 9,001
  • 2
  • 20
  • 29
0

Your if statement needs a closing bracket:

if (a -b >= 0){
    R = 1;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ryan
  • 2,058
  • 1
  • 15
  • 29