#include <stdio.h> #include <conio.h>
int main() { float apple_m=2.8; float banana_m=1.7; float manguo_m=6.5; float apple=0.0; float banana=0.0; float manguo=0.0; float pay,get,back; int chose,screen=1; char check2,check1=1;
while (screen) { clrscr(); printf("\n\n"); printf("\t\t\t*******************************\n"); printf("\t\t\t* How mouch momey *\n"); printf("\t\t\t* (1) Apple-----------2.8$ *\n"); printf("\t\t\t* (2) Banana----------1.7$ *\n"); printf("\t\t\t* (3) Manguo----------6.5$ *\n"); printf("\t\t\t* Other to done *\n"); printf("\t\t\t*******************************\n"); printf("\n"); printf("Witch do you want :"); scanf("%d",&chose); switch (chose) { case 1:
printf("\nInput the weight: kg\b\b\b\b\b\b"); scanf("%f",&apple); printf("\nOk,%.2fkg apples.\n",apple); getchar(); break;
case 2:
printf("\nInput the weight: kg\b\b\b\b\b\b"); scanf("%f",&banana); printf("\nOk,%.2fkg bananas.\n",banana); getchar(); break;
case 3:
printf("\nInput the weight: kg\b\b\b\b\b\b"); scanf("%f",&manguo); printf("\nOk,%.2fkg manguos.\n",manguo); getchar(); break; default : screen=0; } printf("That's all?(y/n)\t"); scanf("%c",&check2); if (check2=='y') screen=0; } pay=apple*apple_m+banana*banana_m+manguo*manguo_m; printf("\nOK!It's %.2f$\n",pay); while (check1) { printf("\nGet : $\b\b\b\b\b"); scanf("%f",&get); if (get<pay) { printf("It's not enaf"); } else check1=0; } back=get-pay; printf("\nShuld back %.2f$",back); getchar(); return 0; } /*问题1:在case语句中,比如在case1中,为什么我一旦取消了getchar()命令, getchar()上面的语句printf("\nOk,%.2fkg apples.\n",apple);就无法执行? 或者说执行了却看不到效果? 问题2:为什么在case语句中的printf("\nOk,%.2fkg apples.\n",apple);第二 个“\n”命令没有效果?而ok前面的那个\n却有效果?*/