else without if error.....need help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aszush
    New Member
    • Mar 2008
    • 1

    else without if error.....need help

    [CODE=Java]//Title: Programming Assignment 1
    //Version:
    //Copyright: Copyright (c) 1999
    //Author: Andrew
    //Company:
    //Description: Computes employee's weekly gross and net pay.
    package prog1;

    import javax.swing.JOp tionPane;

    public class GrossNetPay {
    public static void main (String args[]) {
    //declare variables
    //The numbers we obtain from the user
    int status;
    //The number of hours worked
    double hours;
    //Employee's rate of pay
    double rate;
    //Stores the result of the input dialog box
    String inputString;
    //Gross pay of employee
    double grossPay;
    //Employee tax deduction
    double taxes;
    //Employee pay after deductions
    double net;
    //Full time employee's base pay for 40 hours
    double basePay;
    //Full time employee's pay for overtime hours
    double overtimePay;

    //get number of hours worked
    inputString = JOptionPane.sho wInputDialog ("Number of Hours Worked: ");
    hours = Double.parseDou ble(inputString );
    System.out.prin tln ("Hours worked: " + hours);

    //get employee rate of pay
    inputString = JOptionPane.sho wInputDialog ("Employee's Rate of Pay: $");
    rate = Double.parseDou ble(inputString );
    System.out.prin tln ("Rate of Pay: $" + rate);

    //determine employee's status
    inputString = JOptionPane.sho wInputDialog ("Employee Status is: ( 1-Full Time, 2-Part Time )");
    status = Integer.parseIn t(inputString);

    {
    if (status == 1) { //compute gross and net pay for full time employee
    System.out.prin tln ("Employment status is full-time.");
    }
    //initialize gross pay
    grossPay = 0;


    if (hours <= 40)

    { grossPay = hours * rate;
    taxes = grossPay * .254;
    net = grossPay-taxes-100;

    System.out.prin tln ("The weekly gross pay is $" + grossPay);
    System.out.prin tln ("The weekly net pay is $" + net);
    }
    //initialize basePay
    basePay = 0;

    else
    {
    basePay = 40 * rate;
    overtimePay = (hours - 40) * 1.5 * rate;
    grossPay = basePay + overtimePay;
    taxes = grossPay * .254;
    net = grossPay-taxes-100;

    System.out.prin tln (" The weekly gross pay is $" + grossPay);
    System.out.prin tln (" The weekly net pay is $" + net);
    end if}

    if (status == 2) //compute gross and net pay for part time employee
    System.out.prin tln ("Employment status is part-time.");

    //initialize gross pay
    grossPay = 0;

    grossPay = hours * rate;
    taxes = grossPay * .254;
    net = grossPay-taxes-100;

    System.out.prin tln ("The weekly gross pay is $" + grossPay);
    System.out.prin tln ("The weekly net pay is $" + net);



    }}}
    [/CODE]

    *****Ok I am a entry level programming student and need help on this before I have to turn in for a grade. The purpose of the program is to computer and display gross and net profit while taking into tax being withheld and also a 100 dollar fee for full time employees.

    My problem is it keeps giving me a "else with if" error on line 68 ( the line that actually has the "else" on it)

    not sure why this is happening and need some help before the assignment deadline..

    if you need any other info to answer this question please write back and any help in completing this would be greatly appreciated.
    Last edited by BigDaddyLH; Mar 10 '08, 09:00 PM. Reason: added code tags
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      Here is your problem:

      [CODE=Java]if (hours <= 40) {
      ...
      }
      basePay = 0;
      else {
      ...
      }[/CODE]
      You can't have that assignment where it is. No code must come between the "}" and the "else".

      Comment

      Working...