| Author |
orphaned case error on compile
|
Ryan Foster
Greenhorn
Joined: Sep 23, 2003
Posts: 6
|
|
I get this error when I try to compile my program.... Can you please help. orphaned case case Calculate_Payroll: { There is a small arrow under the letter "c" in case.... Here is my code: case Calculate_Payroll: { double hours; double rate; double result; Utility.separator(80, '='); System.out.print("Amount of hours worked: "); result = hours = Keyboard.readDouble(); System.out.print("Pay rate: "); result = rate = Keyboard.readDouble(); if (hours >=0 && rate >=5.15) { result *=(hours * rate); } Utility.skip(); Utility.printField(20, "Hours worked"); Utility.printField(10, "Pay Rate"); Utility.skip(); Utility.printField(20, Utility.moneyFormat(result)); Utility.skip(); else { Utility.skip(); System.out.print("Error - Negative values are invalid"); break;
|
 |
Joel McNary
Bartender
Joined: Aug 20, 2001
Posts: 1815
|
|
Hell, Ryan, and welcome to JavaRanch! This error usually meas that you are trying to use a "case" keyword outside of a "switch" statement. Could you please post the entire code (inside of [ CODE] and [/CODE] tags, to preserve formatting) so we can see where your switch statement is (assuming it exists!), and maybe we can help you figure out where this case statement got orphaned. [ September 23, 2003: Message edited by: Joel McNary ]
|
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
|
 |
John Smith
Ranch Hand
Joined: Oct 08, 2001
Posts: 2937
|
|
else { Utility.skip(); System.out.print("Error - Negative values are invalid"); break; This doesn't look right, where is the closing brace? Please use the *code* UBB code next time you post code.
|
 |
Ryan Foster
Greenhorn
Joined: Sep 23, 2003
Posts: 6
|
|
Here is all of my code sorry about not using the UBB Code. This is my first post. [ September 23, 2003: Message edited by: Ryan Foster ]
|
 |
Joel McNary
Bartender
Joined: Aug 20, 2001
Posts: 1815
|
|
Well, the problem is that you don't have a switch statement. The switch statement has teh following structure: Please note that the labels and the variable have to be ints (or something int-compatable, such as chars). Also note that you have to use a break statement at the end of each case block. If you don't, then execution will fall down to the next block! In this example, if someInt == 2, then only doSomethingElse() will execute. However, if somInt == 1, then doSomething will execute, and then teh code will fall through to the next statement, which is doSomethingElse(), which will also execute! Just a nit-pick'n' note: generally, final constants are in all caps (CALCULATE_PAY, AUTHOR_INFORMATION, EXIT). This won't make your program run better, but it will make it easier for other Java programmers to read your code.
|
 |
John Smith
Ranch Hand
Joined: Oct 08, 2001
Posts: 2937
|
|
case Calculate_Payroll: { Where is the switch that contains the case?
|
 |
Ryan Foster
Greenhorn
Joined: Sep 23, 2003
Posts: 6
|
|
Thank you for all your help.... Ryan Foster
|
 |
John Smith
Ranch Hand
Joined: Oct 08, 2001
Posts: 2937
|
|
Joel, You beat me again by 2 minutes.
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: orphaned case error on compile
|
|
|