** **
考虑到用餐的膳食价格(膳食的基本费用),小费百分比(作为小费添加的膳食价格的百分比)和税收百分比(膳食价格作为税收的百分比),找到并打印膳食的总费用。
这是我的代码
public class Solution3 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double mealCost = scan.nextDouble(); // original meal price
int tipPercent = scan.nextInt(); // tip percentage
int taxPercent = scan.nextInt(); // tax percentage
double tip = mealCost *(tipPercent/100);
double tax = mealCost*(taxPercent/100);
double total= mealCost+tip+tax;
// cast the result of the rounding operation to an int and save it as totalCost
int totalCost = (int) Math.round(total);
System.out.println("The total meal cost is "+totalCost+" dollars");
}
}
预期产出
The total meal cost is 15 dollars.
我的输出
The total meal cost is 12 dollars.
请帮帮我。
任何帮助都将不胜感激。
答案 0 :(得分:2)
这是一个整数除法问题。
试试这个:
double tip = mealCost *(tipPercent/100.0);
double tax = mealCost*(taxPercent/100.0);
答案 1 :(得分:0)
将答案计算为:
double tip=(mealCost*tipPercent)/100;
double tax=(mealCost*taxPercent)/100;