感觉变得挺对的,可编译时提示错误,麻烦翻译一下error和warning,并指点如何修改
1 #include <stdio.h>2 #include <ctype.h> //ABC Mail Order Grocery朝鲜蓟的售价是1.25美元/磅,甜菜的售价是0.65美元/磅,胡萝卜的售价是0.89美元/磅。
3 #define ARTICHOKE 1.25 // 在添加运输费用之前,他们为满100美元 的订单提供5%的打折优惠。
4 #define BEET 0.65 //对5磅或以下的定单收取3.50美元的运输和装卸费用;超过5磅而不足20磅的定单收取1O.OO美元的运输和装卸费用:20磅 或以上的运输,在8美元基础上每磅加收0.1美元。
5 #define CARROT 0.89 //编写程序,在循环中使用switch语句,以便对输入a的响应是让用户输入所需的朝鲜蓟磅数,b为甜菜 的磅数,c为胡萝卜的磅数,而q允许用户退出订购过程。
6 #define DISCOUNT_LIMIT 100 //然后程序计算总费用、折扣和运输费用(如果有运输费的话),以及总数。
7 #define DISCOUNT_RATE 0.05 //随后程序应该显示所有的购买 信息:每磅的费用、订购的磅数、该订单每种蔬菜的费用、订单的总费用、折扣,如果有的话加上运输费用,以及所有费用的总数。
8 #define FREIGHT_FEE1 3.5
9 #define FREIGHT_LIMIT1 5
10 #define FREIGHT_FEE2 10
11 #define FREIGHT_LIMIT2 20
12 #define FREIGHT_FEE3 8
13 #define FREIGHT_RATE3 0.1
14 int main(void)
15 {
16 char ch;
17 double artichoke=0,beet=0,carrot=0;
18 double sum,discount,freight;
19 printf("Please select your vegetables\n");
20 printf("a.artichoke:$%.2f\n",ARTICHOKE);
21 printf("b.beet:$%.2f\n",BEET);
22 printf("c.carrot:$%.2f\n",CARROT);
23 printf("q.quit\n");
24 printf("price as dollars per pound\n");
25 while((ch=tolower(getchar())!='q')
26 {
27 switch(ch)
28 {
29 case'a':printf("How many pounds of artichoke do you want?\n");
30 scanf("%lf",&artichoke);
31 printf("please select your vegetables:a.b.c.q\n");
32 continue;
33 case'b':printf("How many pounds of artichoke do you want?\n");
34 scanf("%lf",&beet);
35 printf("please select your vegetables:a.b.c.q\n");
36 continue;
37 case'c':printf("How many pounds of artichoke do you want?\n");
38 scanf("%lf",&carrot);
39 printf("please select your vegetables:a.b.c.q\n");
40 continue;
41 default:break;
42 }
43 }
44 printf("%10s%10s%10s%10s\n"," ","artichoke","beet","carrot");
45 printf("%10s%10.2lf%10.2lf%10.2lf\n","price",ARTICHOKE,BEET,CARROT);
46 printf("%10s%10.2lf%10.2lf%10.2lf\n","pound",artichoke,beet,carrot);
47 printf("%10s%10.2lf%10.2lf%10.2lf\n",charge,ARTICHOKE*artichoke,BEET*beet,CARROT*carrot);
48 sum=ARTICHOKE*artichoke+BEET*beet+CARROT*carrot;
49 if(sum<100)discount=0;
50 else discount=sum*DISCOUNT_RATE;
51 if(artichoke+beet+carrot<FREIGHT_LIMIT1)freight=FREIGHT_FEE1;
52 else if(artichoke+beet+carrot<FREIGHT_LIMIT2)freight=FREIGHT_FEE2;
53 else freight=8+(artichoke+beet+carrot-FREIGHT_LIMIT2)*FREIGHT_RATE3;
54 sum=sum-dicount+freight;
55 printf("the price each pound:%.2f\n",sum/(artichoke+beet+carrot));
56 printf("the pound:%.2f\n",artichoke+beet+carrot);
57 printf("the sum:%.2f\n",sum);
58 printf("discount:%.2f\n",discount);
59 return 0;
60 }
||=== Build: Debug in ABCMail (compiler: GNU GCC Compiler) ==
In function 'main':|
26|error: expected ')' before '{' token|
60|error: expected expression before '}' token|
18|warning: unused variable 'freight' [-Wunused-variable]|
18|warning: unused variable 'discount' [-Wunused-variable]|
18|warning: unused variable 'sum' [-Wunused-variable]|
17|warning: unused variable 'carrot' [-Wunused-variable]|
17|warning: unused variable 'beet' [-Wunused-variable]|
17|warning: unused variable 'artichoke' [-Wunused-variable]|
60|warning: control reaches end of non-void function [-Wreturn-type]|
||=== Build failed: 2 error(s), 7 warning(s) (0 minute(s), 0 second(s)) ===|