满意答案
#include"stdio.h"#include"conio.h"structstDrink{floatfPrice;//价格intiLeft;//剩余数};voidPay(stDrink*pstPay){floatfPay=0.0f;if(pstPay->iLeftpstPay->fPrice){printf("找零钱%.1f元,请收好\r\n",fPay-pstPay->fPrice);break;}else{printf("付费成功\r\n");break;}}pstPay->iLeft--;}intmain(){stDrinkstCoca={2.5f,5};//可乐stDrinkstOrage={3.5f,5};//橙汁stDrinkstMilkTea={5.0f,5};//奶茶charcInput=0;while(1){cInput=getch();switch(cInput){case'1'://可乐printf("可乐2.5元,请付费\r\n");Pay(&stCoca);break;case'2'://橙汁printf("橙汁3.5元,请付费\r\n");Pay(&stOrage);break;case'3'://奶茶printf("奶茶5元,请付费\r\n");Pay(&stMilkTea);break;case'#'://设备维修中printf("设备维修中\r\n");break;case'e'://退出程序return0;}}return0;}
00分享举报