【发布时间】:2015-03-11 12:07:45
【问题描述】:
我是 C 程序的初学者,我正在尝试制作餐厅订单菜单。 我从用户输入“Y”开始订购。 然后我希望程序继续接受订单,直到用户输入“N”停止。 当输入“N”时,将打印总销售额。 但是我不能循环播放,你介意帮助我吗?谢谢你。 :)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int code;
float totalPrice=0, totalSales = 0 ;
char choice, choice1;
printf("Welcome to Deli Sandwich! Enter Y to start your order!\n");
scanf("%c", &choice);
while(choice=='Y'|| choice=='y')
{
printf("\n____________________________SANDWICH FILLING______________________________\n");
printf("\n\t\t Menu \t\t Code \t\t Price\n");
printf("\n\t\t Egg \t\t 1 \t\t RM 1.00\n");
printf("\n\t\t Tuna \t\t 2 \t\t RM 2.00\n");
printf("\n\t\t Seafood \t 3 \t\t RM 3.00\n");
printf("\n\t\t Chicken Ham \t 4 \t\t RM 2.50\n");
printf("\nSandwich Filling code: ");
scanf("%d", &code);
switch(code)
{
case 1:
printf("Egg is picked.\n");
totalPrice+= 1;
break;
case 2:
printf("Tuna is picked.\n");
totalPrice+= 2;
break;
case 3:
printf("Seafood is picked.\n");
totalPrice+= 3;
break;
case 4:
printf("Chicken Ham is picked.\n");
totalPrice+= 2.50;
break;
default :
printf("invalid code.");
}
printf("\n_____________________________SANDWICH TYPE________________________________\n");
printf("\n\t\t Menu \t\t Code \t\t Price\n");
printf("\n\t\t Half \t\t 1 \t\t RM 3.00\n");
printf("\n\t\t Whole \t\t 2 \t\t RM 5.00\n");
printf("\nSandwich Type code: ");
scanf("%d", &code);
switch(code)
{
case 1:
printf("Half is picked.\n");
totalPrice+= 3;
break;
case 2:
printf("Whole is picked.\n");
totalPrice+= 5;
break;
default :
printf("invalid code.");
}
printf("\nThe total price is RM%.2f.\n", totalPrice);
printf("Thank You. Please come again!\n");
totalSales+= totalPrice;
printf("\nWelcome to Deli Sandwich! Enter Y to start your order!\n");
scanf("%c", &choice);
}
printf("\nThe total sales is RM%.2f.\n", totalSales);
return 0;
}
再次感谢您:)
【问题讨论】:
标签: c loops input while-loop scanf