Like Tree1Likes
  • 1 Post By rags_to_riches

can i get some help on my c++?

This is a discussion on can i get some help on my c++? within the C++ Programming forums, part of the General Programming Boards category; I have this program that is suppose to show seats in a theater room (and there prices) and after the ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    4

    can i get some help on my c++?

    I have this program that is suppose to show seats in a theater room (and there prices) and after the user picks a seat it should change to 0. If the user picks more than one seat it should combine the prices. I have most of it done except it doesn't combine the prices and it only makes the second selection change to 0 rather than both changing to zero.
    Ill post the question I'm working on and my source code.

    This is the question:
    Problem:
    A theatre seating chart is implemented as a two-dimensional array of ticket prices, like this:
    10 10 10 10 10 10 10 10 10 10
    10 10 10 10 10 10 10 10 10 10
    10 10 10 10 10 10 10 10 10 10
    10 10 20 20 20 20 20 20 10 10
    10 10 20 20 20 20 20 20 10 10
    10 10 20 20 20 20 20 20 10 10
    20 20 30 30 40 40 30 30 20 20
    20 30 30 40 50 50 40 30 30 20
    30 40 50 50 50 50 50 50 40 30
    Write a program that prompts users to pick either a seat or a price. Mark sold seats by changing the price to 0. When a user specifies a seat, make sure it is available. When a user specifies a price, find any seat with that price starting at the front and working to the back of the theatre.


    and this is what i got
    insert
    Code:
    #include <iostream>
    
    
    using namespace std;
    
    
    int movieChoice;
    int seatNum;
    int seatCol;
    int seatRow;
    
    
    int seatPlan [9][10]={10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
    10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
    10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
    10, 10, 20, 20, 20, 20, 20, 20, 10, 10,
    10, 10, 20, 20, 20, 20, 20, 20, 10, 10,
    10, 10, 20, 20, 20, 20, 20, 20, 10, 10,
    20, 20, 30, 30, 40, 40, 30, 30, 20, 20,
    20, 30, 30, 40, 50, 50, 40, 30, 30, 20,
    30, 40, 50, 50, 50, 50, 50, 50, 40, 30};
    int rows,cols;
    
    
    void seatDisplay( int[][10]);
    
    
    void seatDisplay( int a[][10]){
    
    
    for (int i=0;i<9;i++){
    for (int j=0;j<10;j++){
    cout<<a[i][j];
    cout<<" ";
    }
    cout<<endl;
    }
    }
    
    
    
    
    int seatRes(int x){
    
    
    
    
    
    
    cout<<"Seats: Please enter what seat column and row you wish to reserve: \n";
    seatCol:
    for (int i=1;i<=x;i++){
    cout<<"Seat Column 0-9: ";
    cin>>cols;
    if ((cols > 10) || (cols < 0)) {
    cout<<"Invalid column! \n";
    
    
    goto seatCol;
    }
    seatRow:
    cout<<"Seat Row 0-10: ";
    cin>>rows;
    if ((rows > 10) || (rows < 0)) {
    cout<<"Invalid row! \n";
    goto seatRow;
    }
    }
    return 0;
    }
    
    
    int priceComp(int y){
    
    
    int price;
    price=y*seatPlan[seatCol][seatRow]; 
    cout<<"You have reserved"<<y<<"seats.";
    cout<<endl;
    cout<<"Ticket Price: "<<price<<endl;
    
    
    return 0;
    }
    
    
    int main(){
    
    
    
    
    
    
    
    
    
    
    cout<<"Seating Reservation"<<endl;
    seatDisplay(seatPlan);
    cout<<"How many seats would you like to reserve?: ";
    cin>>seatNum;
    seatRes(seatNum);
    cout<<"Reservation";
    seatPlan[rows][cols] = 0;
    cout<<"0 marks your reserved seat \n";
    cout<<"------Movie 1 SEAT PLAN----------- \n";
    seatDisplay(seatPlan);
    priceComp(seatNum);
    
    
    
    
    
    
    
    
    
    
    return 0;
    
    
    }

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,651
    Read this and take it to heart

    The use of goto and global variables also makes this very horrible code, and the latter is part of the cause of your problems. If you reserve two seats, and you're using the same variables for the seat numbers, and you don't set the assignment to 0 after each seat selection, why would you expect the first one would register?
    Elysia likes this.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21