473,545 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

else without if error.....need help

1 New Member
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 2938
BigDaddyLH
1,216 Recognized Expert Top Contributor
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 Recognized Expert Top Contributor
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
97171
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 have written a theme in python for the superkaramba theme engine on kde (see http://netdragon.sourceforge.net - if you are a kde/linux user, it is...
23
3548
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: print "Empty list" which was supposed to be:
14
2176
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 database, and they want certain people to be able to drill down to the data they want, perhaps a few graphs here and there, and then extract selected data...
7
1681
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 present, and then just disable the API. But we are not even able to give an error message when we start the application without mscoree.dll present....
3
3926
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 right direction about what I am not doing correctly? 1.. Write an If Then Else statement that displays the string "Pontiac" in the CarMakeLabel...
32
6088
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 understand Finally runs whether an error was caught or not, I haven't found a use for finally yet.
20
3896
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
18748
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 MySearchButtonClick() If gcfHandleErrors Then On Error GoTo PROC_ERR PushCallStack "MySearchButton" If Me.AllowFlexibility = True Then If...
4
3006
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, custom-made XML parsing engine. Part of this is an if-else block that has to be defined as: <if {condition}> statements... <else/> statements......
0
7391
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7651
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
5962
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5320
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4941
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3438
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1869
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
693
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.