您的程序应该要求用户输入一箱果汁的价格以及购买的纸箱数量。请注意,由于果汁是一种普通的杂货,因此不收取销售税。
然后,确定在 BOGO 报价下购买橙汁的最终成本。
int main() {
//variables
int carton, total;
float cost;
printf("What is the cost of one container of OJ in dollars?\n");
scanf("%4f", &cost);
printf("How many containers are you buying?\n");
scanf("%d", &carton);
if (carton % 2 == 0) {
total = (carton / 2) * cost;
} else {
total = (carton % 2) * cost + (carton - 1 / 2) * cost;
}
//output
printf("The total cost is $%d", total);
return 0;
}