hello, i am in need of some help with a bit of code i been working on. i am getting "illegal start of expression" and "reached end of file while parsing" errors and its been bugging me for awhile as i am not sure why. can anyone help me to get this code to compile correctly and sort out any errors?

import java.util.Scanner;

public class TotalSalesIB
    //main module
    public static void main (String[] args)
        //set up an array to hold the sales
        final int SIZE = 6;
        double[] sales = new double[SIZE];

        // get the sales
        getSales(sales, SIZE);

        // display the total sales
        showTotal(sales, SIZE);

// the getSales module
public static void getSales(double sales[], int size)
    int index; //loop counter

    // get sales for each day.
    for (index = 0; index <= SIZE; size--)
        System.out.print ("Enter the sales for day ", index +1);
        Scanner keyboard = new Scanner(System.in);
        sales[index] = keyboard.nextDouble();

        public static void showTotal(double sales[], int size)
            int index; // loop counter
            double total = 0;  // Accumulator

            // calculate the total sales
            for (index = 0; index <= SIZE; size--)
                total = total + sales[index];
            //display the total sales
            System.out.println ("the total sales are $", total);

3 Years
Discussion Span
Last Post by vergil1983

you are calling methods that don't exist.
there is no 'print' method in System.out that takes a String and an int as parameters, neither is there a 'println' method for these parameters.

you are trying to use the SIZE variable in your getSales method, but you've declared it as a local variable within your main method, so it's out of getSales' scope.

you are starting your showTotal method in the middle of your getSales method, which is not legal according to Java syntax.

first step of debugging is thoroughly reading the error messages. they would have helped you solve this quite easily.
also: make sure your code indentation is done well, that way you'll spot methods within methods instantly.


It should be "System.out.print("Enter the sales for day " + (index +1));"

Just like stultuske say, your showTotal() function should be created separately, not within your getSales() function.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.