输入消费金额 ,输出优惠后的金额。未满500 元无折扣;满500元9折;满 1000 元8折:满2000元7折c语言代码。
时间: 2023-03-27 13:00:31 浏览: 340
以下是 C 语言代码:
#include <stdio.h>
int main() {
float amount, discount;
printf("请输入消费金额:");
scanf("%f", &amount);
if (amount < 500) {
discount = amount;
} else if (amount < 100) {
discount = amount * .9;
} else if (amount < 200) {
discount = amount * .8;
} else {
discount = amount * .7;
}
printf("优惠后的金额为:%.2f\n", discount);
return ;
}
相关问题
.以下程序的功能是输入消费金额 ,输出优惠后的金额。未满500 元无折扣;满500元9折;满 1000 元8折:满2000元7折。c语言怎么写
以下是程序的代码:
#include <stdio.h>
int main() {
float amount, discount;
printf("请输入消费金额:");
scanf("%f", &amount);
if (amount < 500) {
discount = amount;
} else if (amount < 100) {
discount = amount * .9;
} else if (amount < 200) {
discount = amount * .8;
} else {
discount = amount * .7;
}
printf("优惠后的金额为:%.2f元\n", discount);
return ;
}
使用if语句编程实现输入购货金额,输出实际付款金额。购货折扣率如下: 购货金额≤500元 不打折 500元<购货金额≤1000元 9折 1000元<购货金额 8折
### 回答1:
以下是伪代码实现:
输入购货金额
如果购货金额小于等于500元,则实际付款金额为购货金额
否则,如果购货金额小于等于1000元,则实际付款金额为购货金额乘以0.9
否则,实际付款金额为购货金额乘以0.8
输出实际付款金额
你也可以根据具体编程语言进行实现,比如Python:
amount = float(input("请输入购货金额:"))
if amount <= 500:
payment = amount
elif amount <= 1000:
payment = amount * 0.9
else:
payment = amount * 0.8
print("实际付款金额为:", payment)
### 回答2:
可以通过使用if语句来实现输入购货金额,并输出实际付款金额。具体的编程实现步骤如下:
1. 首先,接收用户输入的购货金额,将其保存为一个变量,比如amount。
2. 利用if语句来判断购货金额的大小,并根据不同的折扣率计算实际付款金额。代码如下:
```
if amount <= 500:
payment = amount
elif amount <= 1000:
payment = amount * 0.9
else:
payment = amount * 0.8
```
3. 最后,将计算得到的实际付款金额打印输出。代码如下:
```
print("实际付款金额为:", payment, "元")
```
这样,当用户输入购货金额时,程序会根据不同的购货金额范围计算出实际付款金额,并将结果打印输出。例如,如果输入购货金额为700元,那么程序会按照9折的折扣计算实际付款金额,输出结果为630元。
### 回答3:
这个问题可以通过使用if语句来解决。首先,我们可以通过input()函数来获取用户输入的购货金额。然后,我们可以使用if语句来根据购货金额的不同范围来计算实际付款金额,并将结果输出。
下面是一个使用if语句实现该功能的Python代码示例:
```python
amount = float(input("请输入购货金额:"))
if amount <= 500:
final_amount = amount
elif amount <= 1000:
final_amount = amount * 0.9
else:
final_amount = amount * 0.8
print("实际付款金额为:", final_amount)
```
在上述代码中,我们首先将用户输入的购货金额转换为浮点数类型,并将其存储在变量amount中。然后,我们使用if语句来判断购货金额的范围。
如果购货金额小于等于500元,我们将实际付款金额设为购货金额本身,即final_amount = amount。
如果购货金额大于500元且小于等于1000元,我们将实际付款金额设为购货金额的九折,即final_amount = amount * 0.9。
如果购货金额大于1000元,我们将实际付款金额设为购货金额的八折,即final_amount = amount * 0.8。
最后,我们使用print()函数将实际付款金额输出到屏幕上。
这样,当用户输入购货金额后,程序将根据购货金额的不同范围计算实际付款金额,并将结果输出。
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)