Simple if code not working? Assistanc wanted.
Why is this code not working?
import java.util.Scanner;
public class DiningDollars {
private static Scanner keyboard = new Scanner (System.in);
private static final double SUB_COST = 5;
public static void main (String[] args);
System.out.println("How many dining dollars do you have? ");
double currentDollars = keyboard.nextDouble();
if (currentDollars < (SUB_COST * 3)) {
System.out.println("Take two friends to subway!");
currentDollars -= (SUB_COST*3);
}
System.out.println("You are now left with " + currentDollars);
}
}
Re: Simple if code not working? Assistanc wanted.
"not working" might need a little elaboration: Does this code compile? If not and you can't understand the compiler's messages, post them and indicate the lines of your code to which they refer.
Re: Simple if code not working? Assistanc wanted.
Quote:
Originally Posted by
dunboody
Why is this code not working?
Code:
import java.util.Scanner;
public class DiningDollars {
private static Scanner keyboard = new Scanner (System.in);
private static final double SUB_COST = 5;
public static void main (String[] args);
System.out.println("How many dining dollars do you have? ");
double currentDollars = keyboard.nextDouble();
if (currentDollars < (SUB_COST * 3)) {
System.out.println("Take two friends to subway!");
currentDollars -= (SUB_COST*3);
}
System.out.println("You are now left with " + currentDollars);
}
}
Can you tell us how it's not working?
Re: Simple if code not working? Assistanc wanted.
I'm getting errors on lines 9, 12, and 16. It's saying things like <identifier> expected, and illegal start of type, and ';' expected.
Re: Simple if code not working? Assistanc wanted.
Quote:
Originally Posted by
dunboody
I'm getting errors on lines 9, 12, and 16. It's saying things like <identifier> expected, and illegal start of type, and ';' expected.
Look just above the line causing the error. Your problem is you've got a misplaced semicolon on the line where you declare your main method.
Re: Simple if code not working? Assistanc wanted.
Sometimes the compiler will get *very* confused by a relatively simple mistake and spit out all sorts of messages for the subsequent code. The first thing to do in such cases is to look just above where the messages start.
Re: Simple if code not working? Assistanc wanted.
Yeah, it's the semicolon on the main method line. Thanks, y'all!