Thread: can i get some help on my c++?

  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
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    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?

Popular pages Recent additions subscribe to a feed