By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,666 Members | 1,544 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,666 IT Pros & Developers. It's quick & easy.

else without if error.....need help

P: 1
Expand|Select|Wrap|Line Numbers
  1. //Title:        Programming Assignment 1
  2. //Version:
  3. //Copyright:    Copyright (c) 1999
  4. //Author:       Andrew 
  5. //Company:      
  6. //Description:  Computes employee's weekly gross and net pay.
  7. package prog1;
  8.  
  9. import javax.swing.JOptionPane;
  10.  
  11. public class GrossNetPay {
  12.         public static void main (String args[]) {
  13.         //declare variables
  14.         //The numbers we obtain from the user
  15.         int status;
  16.         //The number of hours worked
  17.         double hours;
  18.         //Employee's rate of pay
  19.         double rate;
  20.         //Stores the result of the input dialog box
  21.         String inputString;
  22.         //Gross pay of employee
  23.         double grossPay;
  24.         //Employee tax deduction
  25.         double taxes;
  26.         //Employee pay after deductions
  27.         double net;
  28.         //Full time employee's base pay for 40 hours
  29.         double basePay;
  30.         //Full time employee's pay for overtime hours
  31.         double overtimePay;
  32.  
  33.     //get number of hours worked
  34.     inputString = JOptionPane.showInputDialog ("Number of Hours Worked: ");
  35.     hours = Double.parseDouble(inputString);
  36.     System.out.println ("Hours worked: " + hours);
  37.  
  38.     //get employee rate of pay
  39.     inputString = JOptionPane.showInputDialog ("Employee's Rate of Pay: $");
  40.     rate = Double.parseDouble(inputString);
  41.     System.out.println ("Rate of Pay: $" + rate);
  42.  
  43.     //determine employee's status
  44.     inputString = JOptionPane.showInputDialog ("Employee Status is: ( 1-Full Time, 2-Part Time )");
  45.     status = Integer.parseInt(inputString);
  46.  
  47.   {
  48.     if (status == 1) { //compute gross and net pay for full time employee
  49.           System.out.println ("Employment status is full-time.");
  50.    }
  51.           //initialize gross pay
  52.           grossPay = 0;
  53.  
  54.  
  55.        if (hours <= 40)
  56.  
  57.         {    grossPay = hours * rate;
  58.             taxes = grossPay * .254;
  59.             net = grossPay-taxes-100;
  60.  
  61.           System.out.println ("The weekly gross pay is $" + grossPay);
  62.           System.out.println ("The weekly net pay is $" + net);
  63.          }
  64.           //initialize basePay
  65.           basePay = 0;
  66.  
  67.        else
  68.          {
  69.             basePay = 40 * rate;
  70.             overtimePay = (hours - 40) * 1.5 * rate;
  71.             grossPay = basePay + overtimePay;
  72.             taxes = grossPay * .254;
  73.             net = grossPay-taxes-100;
  74.  
  75.           System.out.println (" The weekly gross pay is $" + grossPay);
  76.           System.out.println (" The weekly net pay is $" + net);
  77.        end if}
  78.  
  79.     if (status == 2)  //compute gross and net pay for part time employee
  80.           System.out.println ("Employment status is part-time.");
  81.  
  82.           //initialize gross pay
  83.           grossPay = 0;
  84.  
  85.             grossPay = hours * rate;
  86.             taxes = grossPay * .254;
  87.             net = grossPay-taxes-100;
  88.  
  89.           System.out.println ("The weekly gross pay is $" + grossPay);
  90.           System.out.println ("The weekly net pay is $" + net);
  91.  
  92.  
  93.  
  94. }}}
  95.  
*****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.
Mar 10 '08 #1
Share this Question
Share on Google+
2 Replies


BigDaddyLH
Expert 100+
P: 1,216
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
Mar 10 '08 #2

BigDaddyLH
Expert 100+
P: 1,216
Here is your problem:

Expand|Select|Wrap|Line Numbers
  1. if (hours <= 40) {    
  2.    ...
  3. }
  4. basePay = 0;
  5. else {
  6.    ...
  7. }
You can't have that assignment where it is. No code must come between the "}" and the "else".
Mar 10 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.