我正在嘗試編寫一個程序,該計劃將爲用戶輸入工作日,晚上和週末分鐘,並且將吐出每分鐘的平均成本,稅前話單,稅金和總賬單(根據平率/稅率/題目中所給的附加平日分鐘的速率值手機賬單計算器C
#include <stdio.h>
#include <math.h>
#define CENTS_PER_DOLLAR 100
#define FLAT_RATE_IN_CENTS 3999
#define TAX_RATE 0.05
#define ADDITIONAL_WEEKDAY_MIN_IN_CENTS 40
int main()
{
int weekdayMin, nightMin, weekendMin;
float pretaxBill, taxes, totalBill, averageCost;
printf("Please enter the number of weekday minutes, night minutes: ");
scanf("%d %d", &weekdayMin, &nightMin);
printf("Please enter the number of weekend minutes: ");
scanf("%d", &weekendMin);
printf("\n");
printf("Weekday minutes: %d, night minutes: %d, weekend minutes: %d \n", weekdayMin, nightMin, weekendMin);
averageCost = (weekdayMin + weekendMin + nightMin)/(FLAT_RATE_IN_CENTS);
printf("Average minute cost: $%.2f ", averageCost);
if (weekdayMin <= 600)
{
pretaxBill = FLAT_RATE_IN_CENTS;
taxes = FLAT_RATE_IN_CENTS*TAX_RATE;
totalBill = pretaxBill + taxes;
printf("Pretax bill: $%d \nTaxes: $%d \nTotal bill: $%d", pretaxBill, taxes, totalBill);
}
else
{
pretaxBill = (weekendMin - 600)*ADDITIONAL_WEEKDAY_MIN_IN_CENTS;
taxes = pretaxBill*TAX_RATE;
totalBill = pretaxBill + taxes;
printf("Pretax bill: $", pretaxBill, "\nTaxes: $", taxes, "\nTotal bill: $\n", totalBill);
}
return(0);
}
每當我運行程序,它會返回0的平均成本值,我知道的代碼的其餘部分是未格式化正確,當你運行它時,有許多事情是錯誤的,我只是試圖弄清楚如何從平均每分鐘的成本中獲得指令中指定的值,然而,對於程序其他部分的任何其他建議或意見都是值得讚賞的。我仍然很新攝氏度所以我
承擔,這是預期輸出
請輸入平日分鐘,夜的分鐘數:600 50 請進入週末分鐘數:150
平日分鐘:600 ,晚上分:50,週末分鐘:150
平均每分鐘費用:$ 0.05
稅前賬單:$ 39.99
個稅:$ 2.10
總費用:$ 42.09