#include
int main(){
double item1, item2, cheaper, discount, total;
// 输入两个商品的价格
printf("Enter the price of item 1: ");
scanf("%lf", &item1);
printf("Enter the price of item 2: ");
scanf("%lf", &item2);
// 确定哪个商品更便宜
if(item1 < item2){
cheaper = item1;
} else {
cheaper = item2;
}
// 根据价格打折
if(cheaper <= 10){
discount = cheaper * 0.1;
} else {
discount = cheaper * 0.2;
}
// 计算总价
total = item1 + item2 - discount;
// 输出结果
printf("Total expenses after applying discount: $%.2lf", total);
return 0;
}
运行示例:
Enter the price of item 1: 8.99
Enter the price of item 2: 12.49
Total expenses after applying discount: $19.19