团体项目剧院座位切换声明

Group Project Theater seating switch statement

本文关键字:声明 项目      更新时间:2023-10-16

试图使主要内容尽可能简单,但无法使其工作。在代码中,main中有一个switch语句,但我需要将switch语句中的每个情况放入单独的函数中。请帮忙!

选项 = 菜单();

    switch(choice)
    {
    case 1:
        cout <<"Seating Pricesnn";
        for(int count=0;count<ROWS; count++)
        {
            cout <<"The price for row " << (count+1) <<": $";
            cout <<price[count] <<endl;
            getch();
        }
        break;
    case 2:
        cout <<"Purchase Ticketsnn";
        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 Rownn";
        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 Statisticsnn";
        saleStats ();
            break;
    case 5:
        cout <<"Quitn";
        break;
    default: cout <<"Error Inputn";
    }
}

只需这样做:

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 <<"Quitn";
    break;
default: cout <<"Error Inputn";
}

并在必要的功能中做你的 cin/cout 事情。

你甚至自己为saleStats做了这个,所以不确定是什么混乱?