使用C语言写以下代码某商场推出打折促销活动:若顾客购物额不满 100 元则不优惠;达到或超过 100 元则九五折优惠;达到或超过 200 元则九折优惠;达到或超过 500 元则八五折优惠;达到或超过 1000 元则八折优惠。请编写程序,根据购物金额计算优惠后的实际付款金额。
时间: 2023-05-25 18:03:09 浏览: 157
```C
#include <stdio.h>
int main()
{
float total; //购物总金额
float discount = 1.0; //默认优惠无打折,打折系数为1.0
float pay; //应付金额
printf("请输入购物总金额:");
scanf("%f", &total);
if (total >= 100 && total < 200)
{
discount = 0.95; //九五折
}
else if (total >= 200 && total < 500)
{
discount = 0.9; //九折
}
else if (total >= 500 && total < 1000)
{
discount = 0.85; //八五折
}
else if (total >= 1000)
{
discount = 0.8; //八折
}
pay = total * discount;
printf("应付款金额:%.2f元", pay);
return 0;
}
```
相关问题
用C语言编写以下代码:某商场推出打折促销活动:若顾客购物额不满 100 元则不优惠;达到或超过 100 元则九五折优惠;达到或超过 200 元则九折优惠;达到或超过 500 元则八五折优惠;达到或超过 1000 元则八折优惠。请编写程序,根据购物金额计算优惠后的实际付款金额。
```c
#include <stdio.h>
int main() {
float amount, discount, payable;
printf("请输入购物金额:");
scanf("%f", &amount);
if (amount < 100) {
discount = 0;
} else if (amount < 200) {
discount = 0.05;
} else if (amount < 500) {
discount = 0.1;
} else if (amount < 1000) {
discount = 0.15;
} else {
discount = 0.2;
}
payable = amount * (1 - discount);
printf("优惠后的实际付款金额为:%.2f元\n", payable);
return 0;
}
```
用c语言某超市促销规定:购物不超过50元按原价付款;超过50元不超过150元,超过部分按九折付款;超过150元的,超过部分按八折付款。编程序完成超市的计费打折。
以下是用C语言编写的超市计费打折程序:
```c
#include <stdio.h>
int main() {
float total_price, discount_price;
printf("请输入购物总价:");
scanf("%f", &total_price);
if (total_price <= 50) {
discount_price = total_price;
} else if (total_price <= 150) {
discount_price = 50 + (total_price - 50) * 0.9;
} else {
discount_price = 50 + 100 * 0.9 + (total_price - 150) * 0.8;
}
printf("您的折后价格为:%0.2f元\n", discount_price);
return 0;
}
```
程序中,使用了 `if..else if..else` 结构来实现不同购物总价的打折规则。其中,`total_price` 为输入的购物总价,`discount_price` 为计算后的折后价格。
在计算折扣时,首先判断购物总价是否小于等于50元,如果小于等于50元,则按原价付款,即 `discount_price = total_price`。如果购物总价超过50元但不超过150元,则计算超过50元的部分按九折付款,即 `discount_price = 50 + (total_price - 50) * 0.9`。如果购物总价超过150元,则计算超过150元的部分按八折付款,即 `discount_price = 50 + 100 * 0.9 + (total_price - 150) * 0.8`。
最后,使用 `printf` 输出计算后的折后价格。注意,为了保证输出结果的精度,使用了 `%0.2f` 格式化输出,保留两位小数。