尽量保持主体尽可能简单,但无法使其发挥作用。在代码中,main中有一个switch语句,但我需要将switch语句中的每个case放入单独的函数中。请帮忙!
choice = menu();
switch(choice)
{
case 1:
cout <<"Seating Prices\n\n";
for(int count=0;count<ROWS; count++)
{
cout <<"The price for row " << (count+1) <<": $";
cout <<price[count] <<endl;
getch();
}
break;
case 2:
cout <<"Purchase Tickets\n\n";
do
{
cout <<"Please enter the row: ";
cin >>rowChoice;
cout <<"Please enter the seat: ";
cin >>seatChoice;
if(seating[rowChoice][seatChoice] == '*')
{
cout <<"That seat is unavailable please make another selection.\n";
}
else
{
cost = price[rowChoice] + 0;
total += cost;
cout <<"Ticket price: " <<cost <<endl;
cout <<"Please confirm your purchase. Enter 1 for yes, 2 for no.";
cin >>confirm;
if(confirm==1)
{
cout <<"Your ticket purchase has been confirmed.\n";
seating[rowChoice][seatChoice] = TAKEN;
ticketSales++;
}
else if (confirm==2)
{
cout <<"Would you like to purchase another ticket? Enter 1 for yes, 2 for no." <<endl;
cin >>quit;
}
cout <<"Would you like to purchase another ticket? Enter 1 for yes, 2 for no.";
cin >>quit;
}
}
while (quit==1);
break;
case 3:
int viewRow;
cout <<"View Seats by Row\n\n";
cout <<"Enter the row you would like to view";
cin >>viewRow;
seatingChartRow(viewRow);
cout <<"Press 1 to return to the main menu.";
cin >>quit;
break;
case 4:
cout <<"Sales Statistics\n\n";
saleStats ();
break;
case 5:
cout <<"Quit\n";
break;
default: cout <<"Error Input\n";
}
}
答案 0 :(得分:1)
这样做:
choice = menu();
switch(choice)
{
case 1:
seating();
break;
case 2:
buy_tickets();
break;
case 3:
view_seats();
break;
case 4:
saleStats ();
break;
case 5:
cout <<"Quit\n";
break;
default: cout <<"Error Input\n";
}
在必要的功能中做你的cin / cout东西。
你甚至自己为saleStats做过这个,所以不确定是什么混乱?