每日代码1

    科技2022-07-12  135

    #include<stdio.h> int main(void) { float a,b,c,w,y,z; a=b=c=0; float num , A,B,C; char ch; printf(“Please enter letter to buy things(q to quit):\n”); printf(" letter:a b c \n thing :YJ TC HLB \nprice(perB):2.05 1.15 1.09\n"); printf(“How many pounds do you need for”); ch = getchar(); while((ch >= ‘a’ && ch<=‘c’) || ch == ‘q’) { switch(ch) { case ‘a’:printf(“YJ:”); scanf("%f", &w); getchar();//将回车键清除 a += w; break; case ‘b’:printf(“YJ:”); scanf("%f", &y); getchar(); b += y; break; case ‘c’:printf(“YJ:”); scanf("%f", &z); getchar(); c += z; break; case ‘q’:goto end;//goto与目标之间不能再声明变量 } printf(“Please enter letter again to buy nextthings(q to quit):\n”); ch = getchar(); } end:A = a2.05 + b1.15 + c1.09; num = a + b + c;//该式子需要在abc赋值后使用,不然num被赋的值之后不应abc改变而变 if (num 0 )**//此处是而不是=**`` goto end2; else if (num <= 5) B = 6.5; else if (num <= 20) B = 14; else if (num > 20) B = 14 + 0.5(num - 20); if (A >= 100) { C = (A + B)*0.95; printf(“You have 5% discount.\n”); } else C = A + B; printf(“蔬菜重量:%.2f\n蔬菜费用:%.2f\n运费和包装费:%.2f,\n总费用:%.2f”, num , A,B,C); end2:printf(“welcome next coming!”); return 0; }

    Processed: 0.010, SQL: 8