import java.util.*;
import java.math.*;
public class Arithmetic
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
double mealCost = scan.nextDouble(); // original meal price
double tipPercent = scan.nextDouble(); // tip percentage
double taxPercent = scan.nextDouble(); // tax percentage
scan.close();
// Write your calculation code here.
tipPercent = mealCost*tipPercent/100.0;
taxPercent =mealCost*taxPercent/100.0;
//cast the result of the rounding operation to an int and save it as totalCost
double totalCost = mealCost + tipPercent + taxPercent;
// Print your result
int total = (int)totalCost;
System.out.println("The total meal cost is " + total + " dollars.");
}
}
輸入:
20.75
預期輸出:總用餐的費用爲23美元。未能獲得預期的輸出hackerrank DAY2程序
結果輸出:總餐費爲26美元。
這個程序有什麼問題?
你調試你的程序了嗎?你是否確認了單個步驟產生了正確的結果?你爲什麼使用數值''20''和''8''? – f1sh
你沒有使用你的輸入參數,而是用硬編碼的數字覆蓋它們。 –
你的預期結果不應該是33美元嗎?只需簡單地加上所有三個就可以得到33.75! – procrastinator