输入字母后如何必需回车确认呢
程序代码:
#include<stdio.h> #define artichoke 1.25 #define beet 0.65 #define carrot 0.89 #define pound_5 3.50 #define pound_5_20 10.00 #define pound_20 8.00 double judge(double i); double judge(double i) { while(1) { while(scanf("%lf",&i)!=1) { fflush(stdin); printf("格式错误,重新输入\n"); } if(i<0) printf("磅数错误,重新输入\n"); else break; } return i; } int main(void) { double amount,favorable,total_pound,artichoke_pound,beet_pound,carrot_pound,freight; artichoke_pound=beet_pound=carrot_pound=0.0; char ch; printf("请选择您要下的订单,输入a为朝鲜蓟订单,b为甜菜订单,c为胡萝卜订单,q退出订单系统\n"); ch=getchar(); while(ch!='q') { switch(ch) { case 'a':printf("欢迎订购朝鲜蓟,请输入您要的磅数\n"); artichoke_pound=judge(artichoke_pound); printf("请选择您要下的订单,按q退出订单系统并计算费用\n"); fflush(stdin); ch=getchar(); break; case 'b':printf("欢迎订购甜菜,请输入您要的磅数\n"); beet_pound=judge(beet_pound); printf("请选择您要下的订单,按q退出订单系统并计算费用\n"); fflush(stdin); ch=getchar(); break; case 'c':printf("欢迎订购胡萝卜,请输入您要的磅数\n"); carrot_pound=judge(carrot_pound); printf("请选择您要下的订单,按q退出订单系统并计算费用\n"); fflush(stdin); ch=getchar(); break; default: printf("无此项订单,请重新选择\n"); fflush(stdin); ch=getchar(); } } total_pound=artichoke_pound+beet_pound+carrot_pound; favorable=(int)total_pound/100; if(total_pound-20<=-15) { freight=pound_5; amount=artichoke_pound*artichoke+beet_pound*beet+carrot_pound*carrot-favorable*0.05+freight; } else if(total_pound-20>-15&&total_pound-20<=0) { freight=pound_5_20; amount=artichoke_pound*artichoke+beet_pound*beet+carrot_pound*carrot-favorable*0.05+freight; } else { freight=(int)total_pound/1*0.1+8.00; amount=artichoke_pound*artichoke+beet_pound*beet+carrot_pound*carrot-favorable*0.05+freight; } printf("您订购了%.2lf磅朝鲜蓟,%.2lf磅甜菜,%.2lf磅胡萝卜,总计%.2lf磅。\n",artichoke_pound,beet_pound,carrot_pound,total_pound); printf("您需要支付运输和装卸费用$ %.2lf,您可以获得$ %.2lf优惠,总费用为$ %.2lf\n",freight,favorable,amount); return 0; }再输入a20的情况下,会把后面的数据提前录入,输入字母后如何必需回车确认呢