Reputation: 57
Scanner input = new Scanner(System.in);
System.out.print("How much can you afford for meals per day? Enter it now ");
double mealAmount = input.nextDouble();
Upvotes: 1
Views: 2072
Reputation: 44965
This because your tests are performed only after getting the 3 double values. You should move the tests corresponding to each variable just after getting its value thanks to input.nextDouble()
.
Your code should rather be:
System.out.print("How much can you afford for meals per day? Enter it now ");
double mealAmount = input.nextDouble();
if (mealAmount <0)
System.exit(0);
else if (mealAmount < 15.00 && mealAmount >=0)
System.out.println("No meal for you. Tough luck.");
else if (mealAmount >= 15.00 && mealAmount < 30.00)
System.out.println("You can afford bronze meals.");
else if (mealAmount >= 30.00 && mealAmount < 60.00)
System.out.println("You can afford silver meals.");
else if (mealAmount >= 60.00)
System.out.println("You can afford gold meals.");
...
NB: No need to explicitly call System.exit(0)
simply use return
.
Upvotes: 2