Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

orphaned case error on compile

 
Ryan Foster
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
case Calculate_Payroll: {
Where is the switch that contains the case?
 
Ryan Foster
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for all your help....
Ryan Foster
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joel,
You beat me again by 2 minutes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic