Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,911 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,179 people online right now. Registration is fast and FREE... Join Now!




Theature Seating

 
Reply to this topicStart new topic

Theature Seating, C++

smith78910
27 Dec, 2007 - 06:51 PM
Post #1

New D.I.C Head
*

Joined: 20 Dec, 2007
Posts: 9

How come my code is not doing what I want it to do....

Here is my code.....
CODE

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Global variables
const int Number_Rows = 5;    // Number of Rows.
const int Number_Columns = 10;    // Number of Columns.
// Declarations for your functions
void showSeatsChart(float[][Number_Columns]);
void availableSeatsByRow(int, float[][Number_Columns]);
void availableSeats(float[][Number_Columns]);
void getCountOfSoldSeats(float[][Number_Columns]);
void main()
{    
    float Prices[] = {100.00,75.00,50.00,25.00,5.00};  
    // Prices by Row
    float Price[Number_Rows];
    float Seats[Number_Rows][Number_Columns]; // Seats Array.
    int i;
    // Initialize your array here so it will be ready to go for all functions.
   for(int j = 0; j < Number_Rows; j++)
    {
        for(int k = 0; k < Number_Columns; k++)
        {
            //if(Seats[j][k] = 0.00)
        }
    }
    // Ask for price for seat, input price.
    for(i = 0; i < Number_Rows; i++)
    {
       cout << "Please enter the rate for seats in row " << (i + 1) << endl;
       cin >> Prices[i];
    }
    // Selling a Seat.
    cout << "No seats sold yet." << endl;
    showSeatsChart(Seats);
    // Let's sell one seat in row 3
    cout << "Sold one seat in row 3!" << endl;
    Seats[2][0] = 34.00;
    showSeatsChart(Seats);
}
// Seating Chart
void showSeatsChart(float Seats[][Number_Columns])
{
    // Loop through the rows and columns.
    for(int y=0;y<Number_Rows;y++)
    {
        for(int x = 0; x < Number_Columns; x++)
        {
            if(Seats[y][x]==0.00)
            {
                cout<<"#";
            }

           else{
                cout<<"*";
           }
        }
        cout<<endl;
    }
    cout<<endl;
}
// Function to return how many seats are available in a given row.
void availableSeatsByRow(int row, float Seats[][Number_Columns])
{
    string output;                                        // Temp string variable.
    int i=0;                                           // Temp counter.

    for(int x=0;x<Number_Columns;x++)
    {
        if(Seats[row][x]==0.00)
        {
            i++;
            output+=""+(x + 1);
        }
        if(i)
        {
            cout <<"The followingseats are available in row "<<(row +
1)<<":"<<output<<endl;
       }

        else {
            cout<<"There are no seats available in row "<<(row + 1)<< ":"<<endl;
        }
    }
}


// A function to give all the seats available in the entire auditorium.
void availableSeats(float Seats[][Number_Columns])

{
    string output;                                // Temp variable string.
    int i;

    for(int y=0;y <Number_Rows;y++)
    {
        i =0;
        output="";

       for(int x=0;x<Number_Columns;x++)
        {
            if(Seats[y][x]==0.00)
            {
                i++;
                output+=""+(x + 1);
            }

            if(i)
            {
                cout<<"The following seats are available in row"<<(y + 1)<<
":"<< output<<endl;
          }
            else{
                cout<<"There are no seats available in row"<<(y + 1)<<":"<<endl;
            }
        }
    }
}

// How many seats have been sold.
void getCountOfSoldSeats(float Seats[][Number_Columns])
{
    int output=0;                                // Output Variable;

    for (int y =0; y< Number_Rows;y++)
    {
        for (int x= 0;x<Number_Columns;x++)
        {
            if(Seats[y][x]!=0.00)
            {
                output++;
            }
        }
    }  

    cout << "The total number of tickets sold is $" << output << endl;
}




This is what im suppoust to do....

Write a program that can be used by a small theature to sell tickets for performances. the theatures auditorium has 5 rows and 10 columns. the program should display a screen that shows which seats are available and which are taken. Seats that are taken are represented by an * symbol, seats that are available are represented by an # symbol.... it should look similar to this one...

Seats
1 2 3 4 5 6 7 8 9 10
Row 1:
Row 2:
Row 3:
Row 4:
Row 5:

When the program begins, it should ask the user to enter the seat prices for each row. the prices can be stored in a seperate array.

once the prices are entered, the progrma should disply a seating chart similar to the one shown above. the uses may enter the row and seat numbers for tickets being sold. everythime a ticket or group of tickets is purchased, the program should display the total ticket prices and update the seating chart.

the program should keep a total of all ticket sales. the user should be given an option of viewing this amount.

the program should also give the user an option to see a list of how many seats have been sold, how many seats are available in each row, and how many seats are available in the entire auditorium...

if someone can please show me why program is not doing what its suppoust to... thank you...
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Theature Seating
28 Dec, 2007 - 05:45 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,351



Thanked: 51 times
Dream Kudos: 25
My Contributions
You've told us what it is supposed to do, can you describe what it is doing?
User is online!Profile CardPM
+Quote Post

Pontus
RE: Theature Seating
28 Dec, 2007 - 01:00 PM
Post #3

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 544



Thanked: 4 times
Dream Kudos: 275
My Contributions
I found two errors:
-Always make ur main int and let it return 0
-Ur program didnt had a stop so i placed 1 before the end

here is the corrected code:
CODE

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Global variables
const int Number_Rows = 5;    // Number of Rows.
const int Number_Columns = 10;    // Number of Columns.
// Declarations for your functions
void showSeatsChart(float[Number_Rows][Number_Columns]);
void availableSeatsByRow(int, float[][Number_Columns]);
void availableSeats(float[][Number_Columns]);
void getCountOfSoldSeats(float[][Number_Columns]);
int main()
{    
    float Prices[] = {100.00,75.00,50.00,25.00,5.00};  
    // Prices by Row
    float Price[Number_Rows];
    float Seats[Number_Rows][Number_Columns]; // Seats Array.
    int i;
    // Initialize your array here so it will be ready to go for all functions.
   for(int j = 0; j < Number_Rows; j++)
    {
        for(int k = 0; k < Number_Columns; k++)
        {
            //if(Seats[j][k] = 0.00)
        }
    }
    // Ask for price for seat, input price.
    for(i = 0; i < Number_Rows; i++)
    {
       cout << "Please enter the rate for seats in row " << (i + 1) << endl;
       cin >> Prices[i];
    }
    // Selling a Seat.
    cout << "No seats sold yet." << endl;
    showSeatsChart(Seats);
    // Let's sell one seat in row 3
    cout << "Sold one seat in row 3!" << endl;
    Seats[2][0] = 34.00;
    showSeatsChart(Seats);
    cin.sync();
    cin.get();
    return 0;
}
// Seating Chart
void showSeatsChart(float Seats[Number_Rows][Number_Columns])
{
    // Loop through the rows and columns.
    for(int y=0;y<Number_Rows;y++)
    {
        for(int x = 0; x < Number_Columns; x++)
        {
            if(Seats[y][x]==0.00)
            {
                cout<<"#";
            }

           else{
                cout<<"*";
           }
        }
        cout<<endl;
    }
    cout<<endl;
}
// Function to return how many seats are available in a given row.
void availableSeatsByRow(int row, float Seats[][Number_Columns])
{
    string output;                                        // Temp string variable.
    int i=0;                                           // Temp counter.

    for(int x=0;x<Number_Columns;x++)
    {
        if(Seats[row][x]==0.00)
        {
            i++;
            output+=""+(x + 1);
        }
        if(i)
        {
            cout <<"The followingseats are available in row "<<(row +
1)<<":"<<output<<endl;
       }

        else {
            cout<<"There are no seats available in row "<<(row + 1)<< ":"<<endl;
        }
    }
}


// A function to give all the seats available in the entire auditorium.
void availableSeats(float Seats[][Number_Columns])

{
    string output;                                // Temp variable string.
    int i;

    for(int y=0;y <Number_Rows;y++)
    {
        i =0;
        output="";

       for(int x=0;x<Number_Columns;x++)
        {
            if(Seats[y][x]==0.00)
            {
                i++;
                output+=""+(x + 1);
            }

            if(i)
            {
                cout<<"The following seats are available in row"<<(y + 1)<<
":"<< output<<endl;
          }
            else{
                cout<<"There are no seats available in row"<<(y + 1)<<":"<<endl;
            }
        }
    }
}

// How many seats have been sold.
void getCountOfSoldSeats(float Seats[][Number_Columns])
{
    int output=0;                                // Output Variable;

    for (int y =0; y< Number_Rows;y++)
    {
        for (int x= 0;x<Number_Columns;x++)
        {
            if(Seats[y][x]!=0.00)
            {
                output++;
            }
        }
    }  

    cout << "The total number of tickets sold is $" << output << endl;
}


User is offlineProfile CardPM
+Quote Post

smith78910
RE: Theature Seating
29 Dec, 2007 - 09:26 PM
Post #4

New D.I.C Head
*

Joined: 20 Dec, 2007
Posts: 9

QUOTE(smith78910 @ 27 Dec, 2007 - 07:51 PM) *

How come my code is not doing what I want it to do....

Here is my code.....
CODE

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Global variables
const int Number_Rows = 5;    // Number of Rows.
const int Number_Columns = 10;    // Number of Columns.
// Declarations for your functions
void showSeatsChart(float[][Number_Columns]);
void availableSeatsByRow(int, float[][Number_Columns]);
void availableSeats(float[][Number_Columns]);
void getCountOfSoldSeats(float[][Number_Columns]);
void main()
{    
    float Prices[] = {100.00,75.00,50.00,25.00,5.00};  
    // Prices by Row
    float Price[Number_Rows];
    float Seats[Number_Rows][Number_Columns]; // Seats Array.
    int i;
    // Initialize your array here so it will be ready to go for all functions.
   for(int j = 0; j < Number_Rows; j++)
    {
        for(int k = 0; k < Number_Columns; k++)
        {
            //if(Seats[j][k] = 0.00)
        }
    }
    // Ask for price for seat, input price.
    for(i = 0; i < Number_Rows; i++)
    {
       cout << "Please enter the rate for seats in row " << (i + 1) << endl;
       cin >> Prices[i];
    }
    // Selling a Seat.
    cout << "No seats sold yet." << endl;
    showSeatsChart(Seats);
    // Let's sell one seat in row 3
    cout << "Sold one seat in row 3!" << endl;
    Seats[2][0] = 34.00;
    showSeatsChart(Seats);
}
// Seating Chart
void showSeatsChart(float Seats[][Number_Columns])
{
    // Loop through the rows and columns.
    for(int y=0;y<Number_Rows;y++)
    {
        for(int x = 0; x < Number_Columns; x++)
        {
            if(Seats[y][x]==0.00)
            {
                cout<<"#";
            }

           else{
                cout<<"*";
           }
        }
        cout<<endl;
    }
    cout<<endl;
}
// Function to return how many seats are available in a given row.
void availableSeatsByRow(int row, float Seats[][Number_Columns])
{
    string output;                                        // Temp string variable.
    int i=0;                                           // Temp counter.

    for(int x=0;x<Number_Columns;x++)
    {
        if(Seats[row][x]==0.00)
        {
            i++;
            output+=""+(x + 1);
        }
        if(i)
        {
            cout <<"The followingseats are available in row "<<(row +
1)<<":"<<output<<endl;
       }

        else {
            cout<<"There are no seats available in row "<<(row + 1)<< ":"<<endl;
        }
    }
}


// A function to give all the seats available in the entire auditorium.
void availableSeats(float Seats[][Number_Columns])

{
    string output;                                // Temp variable string.
    int i;

    for(int y=0;y <Number_Rows;y++)
    {
        i =0;
        output="";

       for(int x=0;x<Number_Columns;x++)
        {
            if(Seats[y][x]==0.00)
            {
                i++;
                output+=""+(x + 1);
            }

            if(i)
            {
                cout<<"The following seats are available in row"<<(y + 1)<<
":"<< output<<endl;
          }
            else{
                cout<<"There are no seats available in row"<<(y + 1)<<":"<<endl;
            }
        }
    }
}

// How many seats have been sold.
void getCountOfSoldSeats(float Seats[][Number_Columns])
{
    int output=0;                                // Output Variable;

    for (int y =0; y< Number_Rows;y++)
    {
        for (int x= 0;x<Number_Columns;x++)
        {
            if(Seats[y][x]!=0.00)
            {
                output++;
            }
        }
    }  

    cout << "The total number of tickets sold is $" << output << endl;
}




This is what im suppoust to do....

Write a program that can be used by a small theature to sell tickets for performances. the theatures auditorium has 5 rows and 10 columns. the program should display a screen that shows which seats are available and which are taken. Seats that are taken are represented by an * symbol, seats that are available are represented by an # symbol.... it should look similar to this one...

Seats
1 2 3 4 5 6 7 8 9 10
Row 1:
Row 2:
Row 3:
Row 4:
Row 5:

When the program begins, it should ask the user to enter the seat prices for each row. the prices can be stored in a seperate array.

once the prices are entered, the progrma should disply a seating chart similar to the one shown above. the uses may enter the row and seat numbers for tickets being sold. everythime a ticket or group of tickets is purchased, the program should display the total ticket prices and update the seating chart.

the program should keep a total of all ticket sales. the user should be given an option of viewing this amount.

the program should also give the user an option to see a list of how many seats have been sold, how many seats are available in each row, and how many seats are available in the entire auditorium...

if someone can please show me why program is not doing what its suppoust to... thank you...


i got my program to ask for the prices....

i thought i had the rest of the problems done that i explaied at the top but its not doing it. what am i doing wrong.....can someone show me...

how do i enter the row and seat nembers of tickets being sold... how do i display the total ticket prices and udpate the seating chart...

how d o i get my program to keep the total of all toicket sales and how do i get my program to give the user an option of viewing this amount...

and how di i get my program to do the last two questions in my program givcen above....

User is offlineProfile CardPM
+Quote Post

smith78910
RE: Theature Seating
30 Dec, 2007 - 10:30 AM
Post #5

New D.I.C Head
*

Joined: 20 Dec, 2007
Posts: 9

QUOTE(Amadeus @ 28 Dec, 2007 - 06:45 AM) *

You've told us what it is supposed to do, can you describe what it is doing?

i got my program to ask for the prices....

i thought i had the rest of the problems done that i explaied at the top but its not doing it. what am i doing wrong.....can someone show me...

how do i enter the row and seat nembers of tickets being sold... how do i display the total ticket prices and udpate the seating chart...

how d o i get my program to keep the total of all toicket sales and how do i get my program to give the user an option of viewing this amount...

and how di i get my program to do the last two questions in my program givcen above....

User is offlineProfile CardPM
+Quote Post

VernonDozier
RE: Theature Seating
6 Jan, 2008 - 05:45 PM
Post #6

New D.I.C Head
*

Joined: 6 Jan, 2008
Posts: 46

For one thing, you have commented out the initialization of your 2-dimensional seat matrix. Here's your code, unless it's been changed already:

CODE

    // Initialize your array here so it will be ready to go for all functions.
   for(int j = 0; j < Number_Rows; j++)
    {
        for(int k = 0; k < Number_Columns; k++)
        {
            //if(Seats[j][k] = 0.00)
        }
    }



Change the line to:

CODE

Seats[j][k] = 0.00;


No "if" statement is needed here. If the theatre starts out empty, you need to initialize it as "empty" (assuming 0.00 value means empty). Your "showSeatsChart" function is reading this "Seats" array, so it needs to be initialized. Otherwise you have absolutely no idea what values are in those variables. Someone mentioned it before, but you need to change "void main ()" to "int main ()" and have this line at the end of main:

CODE

return 0;


If you initialize the "Seats" array, you will get an accurate theatre printout.

As far as selling tickets, you have not written that function. You've written four functions, but have only called one of them. there are numerous ways of selling tickets. All of them will end up with you changing the "Seats" array. To calculate the total price of all seats will be a procedure similar to your "getCountOfSoldSeats" function.



CODE



void getCountOfSoldSeats(float Seats[][Number_Columns])
{
    float money=0;                                // Output Variable;

    for (int y =0; y< Number_Rows;y++)
    {
        for (int x= 0;x<Number_Columns;x++)
        {
             money = money + Seats[y][x];
        }
    }  

    cout << "The total price of tickets sold is $" << money << endl;
}






Hope this helps.


Whoops. Obviously change the name of that last function to something else since you already have "getCountOfSoldSeats" function.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 01:45PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month