有一个小问题请教
#include<stdio.h>#define CHAOXIANJI 1.25
#define TIANCAI 0.65
#define CARROT 0.89
#define PERCENT 0.05 //100美元以上有0.5折的优惠
#define FUWUFEI1 3.5 //5磅以下
#define FUWUFEI2 10 //5磅以上,20磅以下
#define FUWUFEI3 8+pounds*0.1 //20磅以上
int main()
{
double chaoxianji=0,tiancai=0,carrot=0,percent=0;
double cost,fuwufei,pounds,lastcost;
double cost_chaoxianji=0,cost_tiancai=0,cost_carrot=0;
int type;
printf("请选择一个类别:\n");
printf("a)朝鲜蓟 b)甜菜\nc)胡萝卜 q)退出\n");
while((type=getchar())!='q')
{
switch(type)
{
case 'a':
printf("购买朝鲜蓟的磅数。\n");scanf("%lf",&chaoxianji);printf("请再次选择。\n");break;
case 'b':
printf("购买甜菜的磅数。\n");scanf("%lf",&tiancai);printf("请再次选择。\n");break;
case 'c':
printf("购买胡萝卜的磅数。\n");scanf("%lf",&carrot);printf("请再次选择。\n");break;
}
}
pounds=chaoxianji+tiancai+carrot; //总重量
printf("买了朝鲜蓟%.2f磅,甜菜%.2f磅,胡萝卜%.2f磅,共计%.2f磅。\n",chaoxianji,tiancai,carrot,pounds);
printf("单价:朝鲜蓟:%.2f,甜菜:%.2f,胡萝卜:%.2f\n",CHAOXIANJI,TIANCAI,CARROT); //每种菜的单价
cost_chaoxianji=chaoxianji*CHAOXIANJI; //朝鲜蓟花费
cost_tiancai=tiancai*TIANCAI; //甜菜花费
cost_carrot=carrot*CARROT; //胡萝卜花费
cost=cost_chaoxianji+cost_tiancai+cost_carrot; //买菜花费
if(cost>=100)
percent=cost*0.05; //折扣
if(pounds>0&£s<=5) //服务费
fuwufei=FUWUFEI1;
else if(pounds<20)
fuwufei=FUWUFEI2;
else
fuwufei=FUWUFEI3;
lastcost=cost-percent+fuwufei; //最终消费
printf("买菜花费%.2f,折扣%.2f,服务费%.2f,最终消费%.2f\n",cost,percent,fuwufei,lastcost);
return 0;
}