Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: illegal start of expression

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default illegal start of expression

    I am getting the error "Line 54, illegal start of expression". Line 54 is where my "for" starts. It was running ok earlier, now I can't get this error to go away? Not sure what happened? Any help

    public static void main(String[] args) {
    	double salary;
    	double commission;
    	double totalSales;
    	double annualComp;
    	double salesTarget;
    	double incentive;
    	double accel;
    	double incentive1;
    	double notAccel;
    	double increment;
     
    	//annualComp=commission+salary;
     
    	Scanner keyboard = new Scanner(System.in);
    	System.out.print("What was the salary of the salesperson this year?: ");
    	salary=keyboard.nextDouble();
     
    	System.out.print("What were their total sales for the year?: ");
    	totalSales=keyboard.nextDouble();
     
    	System.out.print("What is the sales target for the salesperson? ");
    	salesTarget=keyboard.nextDouble();
    	accel=(totalSales*.07)+salary;
    	notAccel=(totalSales*.05)+salary;
     
    	if (totalSales >= (.8*salesTarget))
    	{
    	System.out.println("Congrats! You qualify for 7% commission. Your total compensation for the year is " + accel);
    	}
    	else
    	{
    	System.out.println ("Sorry, you didn't qualify for the program. No commission was earned on sales. When you reach " + (salesTarget*.8)+ " you can try me again");
    	};
     
    	String answer;
    	double projSales;
    	double sales1;
     
    	System.out.print("Would you like to see your potential earnings? ");
    	System.out.print("Type 'Y' for Yes  or  'N' for NO ");
    	answer=keyboard.next();
    	sales1=((.5*totalSales)+totalSales);
    	projSales=totalSales;
    	commission = .05 * totalSales;
    	increment= +5000;
     
    	System.out.println("Total Sales   Potential Commission");
    	System.out.println("--------------------------------");
            System.out.println(projSales + "\t\t" + commission);
     
    	for (totalSales=totalSales; totalSales < ((totalSales / .5)+totalSales); totalSales = += increment);
    	{ 
    	if (totalSales > salesTarget)
    	{
    	System.out.println(totalSales + "\t\t" + (totalSales*.07));
    	}
    	else  //(projSales < salesTarget)
    	 {
    	 System.out.println(totalSales + "\t\t" + (totalSales*.05));
    	 };
     
     
    }
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: illegal start of expression

    It was running ok earlier,
    What did you change? Try removing the last change to see if that is where the error is.

    Also please post the full text of the error message that shows where the error is. It has a ^ beneath where the error happens. Wrap the error message in code tags to keep the ^ in the correct location.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Summer (August 20th, 2014)

  4. #3
    Junior Member
    Join Date
    Aug 2014
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: illegal start of expression

    Thats the thing. I dont recall changing it. I copied and pasted the code out into a notepad file (because I was working on an online coder temporarily). I wanted to give something a try that I looked up so I went back to the coder, copied and pasted it back in and now this error is showing.

  5. #4
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: illegal start of expression

    ; += increment);
    I'm not sure that semicolon should be at the end of the loop condition.

    Also, I could be wrong as I am unsure of your logic, but the incremental
    condition of a for loop is generally

    ++increment

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  6. #5
    Junior Member
    Join Date
    Aug 2014
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: illegal start of expression

    Interesting. Not sure why it wasn't erroring earlier.

    Next question:
    	System.out.println("Total Sales   Potential Commission");
    	System.out.println("--------------------------------");
            System.out.println(projSales + "\t\t" + commission);
     
    	for (totalSales=totalSales; totalSales < ((totalSales / .5)+totalSales); totalSales = ++ increment)
    	{ 
    	if (totalSales > salesTarget)
    	{
    	System.out.println(totalSales + "\t\t" + (totalSales*.07));
    	}
    	else  //(projSales < salesTarget)
    	 {
    	 System.out.println(totalSales + "\t\t" + (totalSales*.05));
    	 };

    So, no matter what number I put in, it is still calculating the table out to be just the 5%. It wont calculate a number for 7% when it is meant to. Also, I need the table to output the original sales total with the compensation and then keep outputting in 5000$ sales total increments until 150% of the sales total shows. I can only get it to do one line in the table, showing the original sales amount and thats it.

  7. #6
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: illegal start of expression

    else //(projSales < salesTarget)
    {
    System.out.println(totalSales + "\t\t" + (totalSales*.05));
    };
    <-- get rid

    Get rid of the semicolon here - it may cause (probably is in this case) undefined behaviour
    which is causing the statement to execute as true no matter what you input. When the
    code executes, the first if statement is being ignored.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  8. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: illegal start of expression

    It wont calculate a number for 7%
    What are the values in the variables used in the if statement that controls whether or not the 7% code is executed? Add a println() before the if statement that prints the values used in the if so you can see what the computer sees when it executes that code.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #8
    Junior Member
    Join Date
    Aug 2014
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: illegal start of expression

    Thanks. checking it out now

Similar Threads

  1. Illegal start of expression.
    By finding_my_inner_geek in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 25th, 2013, 08:59 AM
  2. Illegal start of expression
    By Tedstriker in forum What's Wrong With My Code?
    Replies: 22
    Last Post: April 14th, 2013, 06:31 AM
  3. Illegal start of expression!
    By NoobOfTheMonth in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 11th, 2013, 09:53 PM
  4. Help With illegal start of expression
    By inshal in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 9th, 2013, 01:20 PM
  5. need help with illegal start of expression
    By inshal in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 9th, 2013, 11:25 AM