一道C语言程序题目!高手帮忙啊!

来源:百度知道 编辑:UC知道 时间:2024/06/04 05:35:02
某商场打打折促销商品.购买某种商品根据购买数量(x)给予不同的折扣,根据用户输入购买商品的数量及该商品的单价,输出用户应付的金额.折扣信息如下:

______
数量 |
-----
X<5
5=<X<10
10=<X<20
20=<X<30
30=<X
---------
折扣情况|
---------
不打折
1%折扣
2%折扣
4%折扣
6%折扣
-----------

需要用到多重if结构或者switch结构!

#include "stdio.h"

void main()
{
int x;
double p;
double s;
printf("Input number:");
scanf("%d",&x);
printf("Input price:");
scanf("%lf",&p);
if (x<5)
{
s=p*x;
}
else if(x<10)
{
s=p*x*0.99;
}
else if(x<20)
{
s=p*x*0.98;
}
else if(x<30)
{
s=p*x*0.96;
}
else
{
s=p*x*0.94;
}
printf("The total prices is %.2f\n",s);
}

int iNum;/*购买数量*/
int iPay;/*购买费用*/
int iPrice;/*商品单价*/

if (iNum >= 30)
{
iPay = iPrice*iNum*(1-6%);
}
else if (iNum >=20)
{
iPay = iPrice*iNum*(1-4%);
}
else if (iNum >=10)
{
iPay = iPrice*iNum*(1-2%);
}
else if (iNum >=5)
{
iPay = iPrice*iNum*(1-1%);