Member 13390306 Ответов: 1

Как я могу сделать так, чтобы каждый ряд имел свою собственную цену?


Я просто хочу изменить код с попросите меня ввести цену для каждого ряда к не просите меня ввести цену, но уже каждая строка имеет свою собственную цену и это мой код:

#include <iostream>
using namespace std;

int Menu ();
void Show_Seats ();
const char FULL = 'X';
const char EMPTY = '#';
const int rows = 15;
const int columns = 30;
char map [rows][columns];
double price;
int total = 0;
int seat = 450;
int seat2 = 0;
int Quit = 1;
int main ()
{
const int Num_Rows = 15;
int price [Num_Rows];
int row2, column2, cost;
int answer;

    cout << "\t*********************************************************" << endl;
    cout << "\t*                                                       *" << endl;
    cout << "\t*               Welcome to MMU Concert                  *" << endl;
    cout << "\t*                                                       *" << endl;
    cout << "\t*********************************************************" << endl;
    cout << endl << endl;
    for (int count = 0; count < rows; count++)
        {
            cout << "Please enter the price for row " << (count + 1) << ": ";
                cin >> price [count];

        }
    for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < columns; j++)
                map [i][j] = EMPTY;
        }
int choice;
    do
    {
        choice = Menu();
        switch (choice)
        {
            case 1:
                cout << "View Seat Prices\n\n";

                for (int count = 0; count < rows; count++)
                {
                    cout << "The price for row " << (count + 1) << ": ";
                    cout << price [count] << endl;
                }
                break;
            case 2:
                cout << "Purchase a Ticket\n\n";
                do
                {
                    cout << "Please select the row you would like to sit in: ";
                    cin >> row2;
                    cout << "Please select the seat you would like to sit in: ";
                    cin >> column2;
                    if (map [row2] [column2] == '*')
                        {
                            cout << "Sorry that seat is sold-out, Please select a new seat.";
                            cout << endl;
                        }
                    else
                    {
                        cost = price [row2] + 0;
                        total = total + cost;
                        cout << "That ticket costs: " << cost << endl;
                        cout << "Confirm Purchase? Enter (1 = YES / 2 = NO)";
                        cin >> answer;
                        seat = seat - answer;
                        seat2 += answer;

                        if (answer == 1)
                        {
                            cout << "Your ticket purchase has been confirmed." << endl;
                            map [row2][column2] = FULL;
                        }
                        else if (answer == 2)
                        {
                            cout << "Would you like to look at another seat? (1 = YES / 2 = NO)";
                            cout << endl;
                            cin >> Quit;
                        }

                        cout << "Would you like to look at another seat?(1 = YES / 2 = NO)";
                        cin >> Quit;
                    }
                }
                while (Quit == 1);

                break;
            case 3:
                cout << "View Available Seats\n\n";
                Show_Seats ();
                break;
            case 4:
                cout << "Total ticket sales: "<<total<<".\n\n";
                break;
            case 5:
                cout << "Quit\n";
                break;
            default : cout << "Error input\n";
        }
    } while (choice != 5);
return 0;
}
//********************************************************************************
//********************************************************************************
//**                                                                            **
//**                              Define Functions.                          **
//**                                                                            **
//********************************************************************************
//********************************************************************************

int Menu()
{
    int MenuChoice;
        cout << endl << endl;
        cout << " \tMAIN MENU\n";
        cout << " 1. View Seat Prices.\n";
        cout << " 2. Purchase a Ticket.\n";
        cout << " 3. View Available Seats.\n";
        cout << " 4. View Ticket Sales.\n";
        cout << " 5. Quit the program.\n";
        cout << "_____________________\n\n";
        cout << "Please enter your choice: ";
        cin >> MenuChoice;
        cout << endl << endl;
    return MenuChoice;
}

void Show_Seats ()
{
    cout << "\tSeats" << endl;
    cout << "   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30\n";
        for (int count = 0; count < 15; count++)
        {
            cout << endl << "Row " << (count + 1);
            for (int count2 = 0; count2 < 30; count2++)
            {
                cout << " " <<  map [count] [count2];
            }
        }
            cout << endl;
}


Что я уже пробовал:

Я просто хочу посмотреть, как вы, программисты, можете это сделать

Dave Kreskowiak

Так ты просишь нас сделать за тебя домашнее задание?

Этого не случится.

1 Ответов

Рейтинг:
2