int Purchase(){
addon=0;
strcpy(addonC,"00");
system("cls");
printf("\t############################################\n");
printf("\t# #\n");
printf("\t# BEVERAGES #\n");
printf("\t# Reg Large #\n");
printf("\t# [a] Banana MilkTea - 130 145 #\n");
printf("\t# [b] Nagoya - 160 175 #\n");
printf("\t# [c] Hazelnut Smoothie - 150 165 #\n");
printf("\t# [d] Vanilla Matcha - 130 145 #\n");
printf("\t# #\n");
printf("\t############################################\n");
printf("\n\n\tChoice: ");
fflush(stdin);
scanf("%c",&choice);
printf("\tBeverage: ");
switch(choice){
case 'a':
printf("\tBanana MilkTea");
strcpy(Beverage,Item1);
cost=130;
break;
case 'b':
printf("\tNagoya");
strcpy(Beverage,Item2);
cost=160;
break;
case 'c':
printf("Hazelnut Smoothie");
strcpy(Beverage,Item3);
cost=150;
break;
case 'd':
printf("Vanila Matcha");
strcpy(Beverage,Item4);
cost=130;
break;
default:
printf("Invalid Choice. Please try again.");
Purchase(tAmt1);
break;
}
do{
temp=0;
printf("\n\t----------------------------\n");
printf("\t[1]Regular,[2]Large\n\tChoose size: ");
fflush(stdin); scanf("%i",&size);
switch(size){
case 1:
printf("\n\tItem: Regular %s",Beverage);
break;
case 2:
printf("\n\tItem: Large %s",Beverage);
break;
default:
printf("\tInvalid size. Please try again");
break;
}
if(size==1 || size==2)
break;
}while(size!=1 || size !=2);
if(size==2){
cost=cost+15;
printf("\n\tCost: %i",cost);
}
else{
printf("\n\tCost: %i",cost);
}
printf("\n\tAddons? [Y]Yes/[N]No: ");
fflush(stdin);
scanf("%c",&choice);
if(choice=='y' || choice=='Y'){
do{
// system("cls");
printf("\n\t############################\n");
printf("\t# #\n");
printf("\t# ADD-ONS #\n");
printf("\t# [a] Crystals 30 #\n");
printf("\t# [b] Small Pearls 25 #\n");
printf("\t# [c] Big Pearls 30 #\n");
printf("\t# [d] Taro 40 #\n");
printf("\t# #\n");
printf("\t############################\n");
printf("\tEnter your add-on: ");
fflush(stdin);
scanf("%c", &add);
switch(add){
case 'a':
addon=30;
printf("\tAdd Crystals");
strcpy(addonC,"Crystals");
break;
case 'b':
addon=25;
printf("\tAdd Small_Pearls");
strcpy(addonC,"Small_Pearls");
break;
case 'c':
addon=30;
printf("\tAdd Big_Pearls");
strcpy(addonC,"Big_Pearls");
break;
case 'd':
addon=40;
printf("\tAdd Taro");
strcpy(addonC,"Taro");
break;
default:
system("cls");
printf("\tInvalid addon. \nPlease try again.");
break;
}
if(add=='a' || add=='b' || add=='c' || add=='d')
break;
}while(add!='a' || add!='b' || add!='c' || add!='d');
}
else{
}
FILE *f_sales;
f_sales=fopen("sales.txt","a+");
fprintf(f_sales,"%i %s %i %s %i %i\n",date,Beverage,size,addonC,cost,addon);
subTotal=cost+addon;
printf("\n\tSubtotal: %i",subTotal);
tAmt1+=subTotal;
printf("\n\n\tTOTAL AMOUNT: %i",tAmt1);
printf("\n\tpress any key to continue...");
getch();
fclose(f_sales);
do{
printf("\n\n\t*****************\n\n\tAnother purchase? [Y]Yes/[N]No: ");
fflush(stdin);
scanf("%c",&choice);
if(choice=='y' || choice=='Y'){
Purchase();
}
else if(choice=='n' || choice=='N'){
printf("\tCustomer's Payment: ");
fflush(stdin);
scanf("%i",&cPay);
// Total=tAmt1;
printf("\tCustomer's Change: %i",cPay-tAmt1);
printf("\tGo back to main menu? [Y]Yes | [N]No: ");
fflush(stdin);
scanf("%c",&choice);
if(choice=='y' || choice=='Y')
SaleMenu();
else{
printf("\tHave a good day!\n");
getch();
printf("\tProgram will now Exit...");
}
}
else{
printf("\n\tInvalid choice. Try again.");
system("cls");
}
}while(choice!='n' || choice=='N' || choice=='y' || choice=='Y');
//return tAmt1;
}
答案 0 :(得分:1)
错误发生在
scanf("%i",cPay);
最好给出指针,就像你在其他地方做的一样......
scanf("%i",&cPay);
我还建议使用%d
代替%i
。但如果您的某个客户只知道十六进制数字,请保留%i
!
再见,
弗朗西斯