Monty Osman
Monty Osman

Reputation: 11

Error: reached end of file while parsing

I am getting this error:

Error: reached end of file while parsing

I know it means I need to close the curly bracket somewhere, but I have tried everything. I figured line 45 is the brace that needs to be closed, but I'm not sure how. This is a program for helping find the smallest number of coins needed to make the integer inputted by the user. For example, 37 would yield 2 Quarters, 1 Dime, and 2 pennies.

import java.util.Scanner;
public class Change {
	public static void main(String[] args){

		Scanner sc = new Scanner (System.in);
Int n = sc.nextInt("Enter a positive integer" );
		int number1, number2; // Division operands
      int quotient;         // Result of division

	{if (QtrCnt > 0)

	if (QtrCnt > 1)
	System.out.println(QtrCnt + " quarters");
	else
	System.out.println(QtrCnt + " quarter");
}
if (DimeCnt > 0)
{
if (DimeCnt > 1)
System.out.println(DimeCnt + " dimes");
else
System.out.println(DimeCnt + " dime");
}
if (NicklCnt > 0)
{
if (NicklCnt > 1)
System.out.println(NicklCnt + " nickles");
else
System.out.println(NicklCnt + " nickle");
}
if (PennyCnt > 0);
{
if (PennyCnt > 1);
System.out.println(PennyCnt + " pennies");
System.out.println(PennyCnt + " penny");
}

int q = 25;
int d = 10;
int n = 5;
int p = 1;
if (a < 0);

System.out.println("ERROR");
{
 String (money >=25); { int numQuarters = money/ 25; }
 money -= numQuarters * 25;
 QtrCnt = (num1 - num1 % 25) / 25;
 num1 = num1 - QtrCnt * 25;

  String(money >=10); { int numDimes = money/ 10; }
 money -= numDimes * 10;
 DimeCnt = (num1 - num1 % 10) / 10;
num1 = num1 - DimeCnt * 10;

   String (money >=5); { int numNickles = money/ 5; }
  money -= numNickles * 5;
  NicklCnt = (num1 - num1 % 5) / 5;
num1 = num1 - NicklCnt * 5;

    String (money >=1); { int numPennies = money/ 1; }
  money -= numPennies * 1;
  PennyCnt = (num1 - num1 % 1) / 1;
num1 = num1 - PennyCnt * 1;
}
   }

Upvotes: 0

Views: 1565

Answers (1)

Mark
Mark

Reputation: 1498

Yes, you are in fact missing the closing bracket for the class.

You also have a lot of brackets that basically don't do anything. Remember that if you don't put a { immediately after the () of an if, it won't belong to the if statement.

I cleaned up your code a little and got this:

import java.util.Scanner;

public class Change 
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner (System.in);
        Int n = sc.nextInt("Enter a positive integer" );
        int number1, number2; // Division operands
        int quotient;         // Result of division

        {   // <- Won't do anything
            if (QtrCnt > 0)
                if (QtrCnt > 1)
                    System.out.println(QtrCnt + " quarters");
                else
                    System.out.println(QtrCnt + " quarter");
        }

        if (DimeCnt > 0)
        {
            if (DimeCnt > 1)
                System.out.println(DimeCnt + " dimes");
            else
                System.out.println(DimeCnt + " dime");
        }

        if (NicklCnt > 0)
        {
            if (NicklCnt > 1)
                System.out.println(NicklCnt + " nickles");
            else
                System.out.println(NicklCnt + " nickle");
        }

        if (PennyCnt > 0);
        {
            if (PennyCnt > 1);
                System.out.println(PennyCnt + " pennies");
            System.out.println(PennyCnt + " penny");
        }

        int q = 25;
        int d = 10;
        int n = 5;
        int p = 1;

        if (a < 0);
            System.out.println("ERROR");

        { // <- Won't do anything
            String (money >=25); { int numQuarters = money/ 25; }
            money -= numQuarters * 25;
            QtrCnt = (num1 - num1 % 25) / 25;
            num1 = num1 - QtrCnt * 25;

            String(money >=10); { int numDimes = money/ 10; }
            money -= numDimes * 10;
            DimeCnt = (num1 - num1 % 10) / 10;
            num1 = num1 - DimeCnt * 10;

            String (money >=5); { int numNickles = money/ 5; }
            money -= numNickles * 5;
            NicklCnt = (num1 - num1 % 5) / 5;
            num1 = num1 - NicklCnt * 5;

            String (money >=1); { int numPennies = money/ 1; }
            money -= numPennies * 1;
            PennyCnt = (num1 - num1 % 1) / 1;
            num1 = num1 - PennyCnt * 1;
        }
   }
 // <- This is where you're missing the class bracket

Please try to improve the way you're formating your code because it really helps finding these kinds of mistakes very quickly.

Keep in mind that I only reformated the code, I did not change what it does or check if it even works.

Upvotes: 1

Related Questions