#include <iostream>
#include <iomanip>
#include <fstream>
#include "groupProj.h" 
using namespace std;

const char Avail = '#';
const char Taken = '*';
const int r = 15;
const int c = 30; 
char SEATS[r][c];



int main()
{
    // Declarations for main
    ifstream inputPrices; 
    double seatPrices[15];
    int row;
    int column;
    double cost;
    double totalSales = 0.0;
    int answer;
    int confirm; 
    int choice; 
    int seat1 = 450;
    int seat2 = 0;


//**********************************************
    // Open the file
    inputPrices.open("SeatPrices.txt");

    if (!inputPrices)
    {
        cout << "Error opening the file!\n";
        return 1;
    } 

    // Input the prices from file into an array
    for (int h = 0; h < 15; h++)
    {
        inputPrices >> seatPrices[h];
    } 
//**********************************************

    cout << "          Welcome to Rachel's Theater!\n\n\n";

    for (int i = 0; i < 15; i++)
    {
        for (int j = 0; j < 30; j++)
        {
            SEATS[i][j] = Avail; 
        }
    }


    do
    {
        displayMenu();
        cin >> choice;
        cout << "\n"; 

        switch (choice)
        {
            case 1: cout << "         You have chosen to view the seat prices.\n\n";

                    for (int k = 0; k < 15; k++)
                    {
                        inputPrices >> seatPrices[k];

                        cout << "         The price for row " << (k + 1)
                            << " is: $" << seatPrices[k] << endl; 
                        cout << "\n"; 
                    }
                    break;

            case 2: cout << "         You have chosen to purchase a ticket.\n\n";
                do
                {
                    cout << "      *Be sure to pick a valid row, 1-15 and seat, 1-30* \n\n"; 
                    cout << "         Please select the row you'd like to sit in: ";
                    cin >> row;
                    cout << "         Please select the seat you'd like to sit in: ";
                    cin >> column;

                    if (SEATS[row-1][column-1] == '*')
                    {
                        cout << "\n";
                        cout << "         Sorry, that seat is taken, please select another.\n\n";
                        break;
                    }

                    if (SEATS[row-1][column-1] != '*')
                    {

                        cost =  seatPrices[row-1] + 0; // To get the correct price

                        cout << "         That ticket costs: " << cost << endl;
                        cout << "         Confirm Purchase? Enter (1 = YES / 2 = NO): ";
                        cin >> answer;

                    if (answer == 1)
                    {
                        seat1 = seat1 - answer;
                        seat2 += answer; 
                    } 
                        if (answer == 1)
                        {
                            totalSales += seatPrices[row-1];
                            cout << "\n";
                            cout << "         Your ticket purchase has been confirmed.\n\n";
                            SEATS[row-1][column-1] = Taken;
                            break;

                        }

                        else if (answer == 2)
                        {
                            cout << "\n";
                            cout << "         Would you like to purchase a different seat? (1 = YES / 2 = NO): ";
                            cin >> confirm;
                            cout << "\n";
                        }
                    }
                } while (confirm == 1);
                    break;

            case 3: cout << "        You have chosen to view the available seats.\n\n";
                    displaySeats();
                    cout << "\n";
                    break;

            case 4: cout << "         You have chosen to view the ticket sales.\n\n";
                    cout << "         Total of sales so far: $" << totalSales << endl;
                    cout << "\n"; 
                    break;

            case 5: cout << "         You have chosen to view the number of seats.\n\n";
                    cout << "         The number of seats available: " << seat1 << endl;
                    cout << "         The number of seats sold: " << seat2 << endl; 
                    cout << "\n";
                    break; 

            case 6: cout << "         Ending the Program.\n\n";
                    break;

            default : cout << "         Please enter a choice in the range of 1-5.\n\n";

        }

    } while (choice != 6);

    return 0;
} 

//********************Function mains************************
void displayMenu()
{
    cout << "               Menu Selection\n\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. View Number of Seats\n"; 
    cout << "            6. Exit\n\n";
    cout << "         Enter a choice from the Menu Selection: ";

}

void displaySeats()
{
    cout << "\n"; 
    cout << "                              Seats\n\n";
    cout << "      1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0\n";

    for (int count1 = 0; count1 < 15; count1++)
    {
        cout << endl << "Row " << (count1 + 1);

        for (int count2 = 0; count2 < 30; count2++)
        {
            cout << " " << SEATS[count1][count2];
        }
    }

    cout << "\n";
}

Recommended Answers

All 7 Replies

Okay, the problem i'm having is, I have one last thing to do on this project and have spent a few hours trying to figure out, how do i do it?

I need to figure out how many seats are available in each row.

I will use a for loop to display the seats in each row, but I am unsure on how to actually figure out how many seats are available in each row, so that it changes as it counts, and doesn't repeat the same thing.

The seats available in each row will be displayed within "Case: 5".

Help Please!

To know how many seats are available in each row, you need to use the same loop structure you have in the DisplaySeats( ) function to count up the number of seats marked available as you loop through each row.

Be sure to reset your counter to 0 as you start each new row's count.

How do i reset the counter to 0 for each new row :o ?

Sorry, I'm obviously new :s

The general structure is something like:

for( i = 0; i < maxrows; i++ )
{
    sum = 0;
    for( j = 0; j < rowsize; j++ )
    {
        //add to sum the value from each row element
        //dislay the row's sum
    }
}
for (int i = 0; i < 15; i++)
    {
        int sum = 0;
        for (int j = 0; j < 30; j++)
        {
            sum =  + sum;

            cout << "The sum is " << sum << endl; 
        }
    } 

---------------------------------------------------------------

okay this is what i've got but i'm getting alot of weird numbers because i'm not sure
of what is actually being added to sum.

i've been doing this program all day... my brain must be getting tired. :(

btw, that's not my final output statement, I was only testing.

To count how many seats have been sold, what do you need to be looking at? Each row of the seats array contains some number of '#' and '*' characters. You want to be counting how many are still '#'.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.