某商品出售按购买数量打折,如果购买数量超过30个则按95折销售,输入商品数量和商品单价(元),输出所购商品的总价
时间: 2023-05-14 10:05:44 浏览: 46
好的,根据您提供的信息,我可以为您计算所购商品的总价。请告诉我商品数量和商品单价(元)。
(假设商品数量为n,商品单价为p)
如果n超过30个,则总价为np*0.95元。
如果n不超过30个,则总价为np元。
请问还有什么我可以帮助您的吗?
相关问题
⑴某商品出售按购买数量打折,如果购买数量超过30个则按95折销售,输入商品数量和商品单价(元),输出所购商品的总价
好的,根据您提供的信息,我给出以下程序代码:
```python
num = int(input("请输入购买数量:"))
price = float(input("请输入商品单价(元):"))
if num > 30:
total = num * price * 0.95
else:
total = num * price
print("所购商品的总价为:%.2f元" % total)
```
如果您购买数量不超过30个,则按照单价计算总价;如果购买数量超过30个,则按照95折的价格计算总价。程序会输出所购商品的总价,保留两位小数。
c语言某商品出售按购买数量打折,如果购买数量超过30个则按95折销售,输入商品数量和商品单价(元),输出所购商品的总价
好的,根据您提供的信息,我已经能够为您提供答案了。
假设您输入的是商品数量 (num)和商品单价(price),那么计算所购商品的总价的公式应该是:total_price = num * price * (num > 30 ? 0.95 : 1)。
其中,三目运算符 ? : 用来判断购买数量是否大于30,并将计算结果乘以0.95(即95折)来进行打折。
如果需要代码实现,可以参考以下代码:
```
#include <stdio.h>
int main() {
int num;
float price;
printf("请输入商品数量和单价: ");
scanf("%d %f", &num, &price);
float total_price = num * price * (num > 30 ? 0.95 : 1);
printf("所购商品的总价为: %.2f元\n", total_price);
return 0;
}
```
请注意,这里使用了 %.2f 来表示保留两位小数,确保输出的结果是精确的。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![.pdf](https://img-home.csdnimg.cn/images/20210720083646.png)