473,395 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

else without if error.....need help

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
2 2934
BigDaddyLH
1,216 Expert 1GB
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
1,216 Expert 1GB
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

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

Similar topics

11
by: dmbkiwi | last post by:
I am new to this group, and relatively new to python programming, however, have encountered a problem I just cannot solve through reading the documentation, and searching this group on google. I...
23
by: Invalid User | last post by:
While trying to print a none empty list, I accidentaly put an "else" statement with a "for" instead of "if". Here is what I had: if ( len(mylist)> 0) : for x,y in mylist: print x,y else:...
14
by: LP | last post by:
Hi, I will be taking on a new project developing a web-based "reporting system". The first requirement I got from BI group is "we just want to look at the data". Basically, there is a huge...
7
by: Staale L. Hansen | last post by:
We have an application which uses some mixed-mode code to expose a .NET 1.1 managed API. Only the necessary files are compiled with /clr. We want to be able to load the application without .NET...
3
by: Amy | last post by:
Hi, I have 6 If Then Else statements I was supposed to write. I did so but I know that they have to be wrong because they all look the same. Could someone take a look at them and point me in the...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
20
by: John Salerno | last post by:
I'm starting out with this: try: if int(text) 0: return True else: self.error_message() return False except ValueError: self.error_message()
8
by: pelicanstuff | last post by:
Hi - Was wondering if anybody could tell me why this rather crappy code is giving me an 'Else without If' error on compile? All the Elses and Ifs look ok to me but there's a few. Private Sub...
4
by: Tangleman | last post by:
I have a schema that defines a programming language for a script that drives a sequentially executing process. It defines the structure of a script that has to interact with a pre-existing,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.