0
這是代碼。基本上,在我輸入第二個客戶賬單金額後,它會過早地讀我一個提示,並詢問是否有另一個客戶。我希望它能問我是否有另一位顧客,但我不希望它詢問有關提示,直到我輸入「n」。有什麼想法嗎?小費計算器聲明混淆
import java.util.Scanner;
public class H3_TipCalc {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.println("Please enter your bill amount.");
double bill = input.nextDouble();
String multiplecust = ("Y");
//int mc=1;
while (multiplecust.equalsIgnoreCase("y"))
{
Scanner usrin = new Scanner (System.in);
System.out.println("Is there another customer? y or n?");
multiplecust = usrin.nextLine();
//mc++;
if (multiplecust.equals("y")){
System.out.println("Please enter their bill amount.");
}
else if (multiplecust.equals("n")){
System.out.println("What tip prcentage would you like to use? Enter as a decimal.");
}
double tip = usrin.nextDouble();
System.out.println("Your tip owed will be " + bill*tip + ".");
}
}
}