|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这道题目我这么解的,但是调试的过程中发现一个问题,见下图
#include<stdio.h>
#include<ctype.h>
const double PRISE1=1.25;
const double PRISE2=0.65;
const double PRISE3=0.89;
const int AMOUNT1=5;
const int AMOUNT2=20;
const double TRANSPORT1=3.5;
const double TRANSPORT2=10.00;
const double TRANSPORT3=8;
const int BREAK=100;
int main()
{
char ch;
double A,B,C;//朝鲜蓟,甜菜,胡萝卜的磅数
double cost1,cost2,cost3;//朝鲜蓟,甜菜,胡萝卜的费用
double amount,trans,cut,cost,final;//总磅数,运费,折扣,花费,折扣后费用
double average,sum;//平均费用,运费后费用
printf("Enter a,b or c to choose,(# to stop)\n");
while((ch=getchar())!='#'){
if (ch == '\n')
continue;
while (getchar() != '\n')//这段为什么有那个作用?
continue;
ch = tolower(ch);
switch(ch){
case'a':printf("Enter the amount of 朝鲜蓟:");
scanf("%lf",&A);
break;
case'b':printf("Enter the amount of 甜菜:");
scanf("%lf",&B);
break;
case'c':printf("Enter the amount of 胡萝卜:");
scanf("%lf",&C);
break;
default:printf("%c is not a valid choice.\n",ch);
}
printf("Enter a,b or c to choose,(# to stop)");
}
amount=A+B+C;
if(amount<AMOUNT1)
trans=TRANSPORT1;
else if(amount<AMOUNT2)
trans=TRANSPORT2;
else
trans=TRANSPORT3+amount*0.1;
cost1=A*PRISE1;
cost2=B*PRISE2;
cost3=C*PRISE3;
cost=cost1+cost2+cost3;
if(cost>=BREAK)
cut=cost*0.05;
else
cut=0;
final=cost-cut;
average=final/amount;
sum=final+trans;
printf("您订购的总磅数为:%.2f,每磅费用为:%.2f.\n",amount,average);
printf("订单总费用:%.2f,折扣:%.2f.朝鲜蓟共:%.2f磅,$%.2f;甜菜共:%.2f磅,$.2f;胡萝卜共%.2f磅,$%.2f\
",final,A,cost1,B,cost2,C,cost3,cut);
printf("\n");
printf("运输费$%.2f,总计费用为$%.2f",trans,sum);
return 0;
}
当三个值不全输入的时候,就这样了- -。求指教,给改的和谐下。
|
|