用c语言程序代码表达题目描述:商场夏季促销,购物500元以下,不打折;购物500元(含)以上,95折;购物1000元(含)以上,9折;购物3000元(含)以上,85折;购物5000元(含)以上,8折。根据消费金额,确定用户实际需要支付的数目。 输入:输入一个实数,表示消费金额。 输出:输出一个实数,表示用户实际需要支出的数目,保留两位小数。
时间: 2023-05-20 08:04:26 浏览: 168
以下是用C语言编写的程序代码,可以实现商场夏季促销的功能:
#include <stdio.h>
int main() {
float amount, discount, total;
printf("请输入消费金额:");
scanf("%f", &amount);
if (amount < 500) {
discount = 1.0;
} else if (amount < 1000) {
discount = 0.95;
} else if (amount < 3000) {
discount = 0.9;
} else if (amount < 5000) {
discount = 0.85;
} else {
discount = 0.8;
}
total = amount * discount;
printf("用户实际需要支付的数目为:%.2f\n", total);
return 0;
}
当用户输入消费金额后,程序会根据金额大小来确定折扣率,然后计算出用户实际需要支付的数目,并输出结果。例如,如果用户输入的消费金额为600元,则程序会计算出折扣率为0.95,用户实际需要支付的数目为570元。
相关问题
用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` 格式化输出,保留两位小数。