我正在尝试编写一个程序,该程序将获取用户在工作日、晚上和周末的分钟数,并输出每分钟的平均成本、税前账单、税金和总账单(根据统一费率/税率/额外工作日问题中给出的分钟率值
#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。我知道其余代码的格式不正确,并且当您运行它时,会出现很多错误。我只是想弄清楚如何从每分钟的平均成本中获取说明中指定的值。但是,感谢您对程序其他部分的任何其他建议或意见。我对 C 还是很陌生,所以请多多包涵
这是预期的输出
请输入工作日分钟数,夜间分钟数:600 50 请输入周末分钟数:150
平日分钟:600,夜间分钟:50,周末分钟:150
平均分钟费用:0.05 美元
税前账单:39.99 美元
税费:2.10 美元
总账单:42.09 美元