#include
main(){
float price;
int flag=1;
while(flag){
printf("请输入消费金额");
scanf(price,%f);
if(price<0)
{printf("对不起,您输入的数据有误,请重新输入 /n");
continue;}
else if(price<100)
{printf("折扣率是0%/n");
printf("您的应付金额为" & price,%f);
break;
}
else if(price<200)
{printf("折扣率是5%/n");
printf("您的应付金额为" & price*0.95,%f);
break;}
else if(price<500)
{printf("折扣率是10%/n");
printf("您的应付金额为" & price*0.90,%f);
break;}
else if(price<1000)
{printf("折扣率是15%/n");
printf("您的应付金额为" & price*0.85,%f);
break;}
else if(price>=1000)
{printf("折扣率是20%/n");
printf("您的应付金额为" & price*0.80,%f);
break;}
else
break;
}
}
#include
main()
{int d;
float f,p;
printf("请输入消费金额:");
scanf("%f",&p);
switch(int(p/100.0))
{case 0:d=0;f=p;break;
case 1:d=5;f=p*0.95;break;
case 2:
case 3:
case 4:d=10;f=p*0.9;break;
case 5:
case 6:
case 7:
case 8:
case 9:d=15;f=p*0.85;break;
default:d=20;f=p*0.8;break;
}
printf("折扣是%d%%,金额是%f.\n",d,f);
while(1);
return 0;
}
我验证过了,完全符合要求,希望对你有所帮助!
用if比较好做,switch不是一般的麻烦 (下面程序可直接粘贴运行)
#include
main()
{
float d,t;
int p,f;
scanf("%d",&p);
if (p>=100&&p<200)d=0.05;
else if (p>=200&&p<500) d=0.10 ;
else if (p>=500&&p<1000) d=0.15;
else if (p>=1000)d=0.20;
else d=0.0;
t=p*d;
f=p-t;
printf("%d,",f);
}
# include
void main()
{int i;
float p;
scanf("%f",&p);
if(p<100)
i=0;
else if(p>=100&&p<200)
i=1;
else if(p>=200&&p<500)
i=2;
else if(p>=500&&p<1000)
i=3;
else
i=4;
printf("折扣率%d\% \n ",(i*5));
switch(i)
{case 0:
printf(" 您的应付金额为%f",p);
break;
case 1:
printf("您的应付金额为 %f",p*0.95);
break;
case 2:
printf(" 您的应付金额为%f",p*0.90);
break;
case 3:
printf(" 您的应付金额为%f",p*0.85);
break;
case 4:
printf(" 您的应付金额为%f",p*0.80);
}
}
#include
void main()
{
int p,d,s,k;
scanf("%d",s);
switch(p)
{
case: p<100 k = 0;break;
case: p>=100&&p<200 s = s*0.05;k = 0.05;break;
case: p>=200&&p<5000 s = s*0.1;k = 0.1;break;
case: p>=500&&p<1000 s = s*0.15;k = 0.15;break;
case: p>=1000 s = s*0.2;k = 0.2;break;
}
printf("\n消费金额:%d,折扣率:%d,诗赋金额:%d",s/(k),k,s);
}