How can I make this program work? Problem with arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • babe20042004
    New Member
    • Oct 2008
    • 8

    How can I make this program work? Problem with arrays

    Code:
    #include<iostream>
    #include<string>
    
    using namespace std;
    void details( string fNum,int dHour,int dMin,int aHour,int aMin, string aircraft);
    
    int main()
    {
     //Flights tB:Trinidad-Barbados,tN:Trinidad to New York,tL:Trinidad to London.
            int dHour;
            int dMin;
            string fNum;
            int aHour;
            int aMin;
            int durHour;
            int durMin;
            string aircraft;
            int dOption;
            bool availabe=true;
            int seats[max_seat_rows][max_seat_cols]={0};
            int resAmt;
            int empty=0;
    
    //Recording Reservations for Passengers
            cout<<"\nWhat is your destination?\n"<<endl<<"1) Trinidad to Barbados"<<endl
                                                   <<"2) Trinidad to New York"<<endl
                                                   <<"3) Trinidad to London\n"<<endl;
            cout<<"Please enter either 1,2 or 3."<<endl;
            cin>>dOption;
    
            switch (dOption)
            {
                    case 1:
                            dHour=7;
                            dMin=0;
                            fNum="USC 215";
                            aHour=7;
                            aMin=45;
                            durHour=0;
                            durMin=45;
                            aircraft="MD 82";
                            max_seat_rows=15;
                            max_seat_cols=4;
    
    
                    break;
    
                    case 2:
                            dHour=6;
                            dMin=0;
                            fNum="USC 400";
                            aHour=3;
                            aMin=0;
                            durHour=6;
                            durMin=0;
                            aircraft="Boeing 737";
                            max_seat_rows=32;
                            max_seat_cols=6;
                    break;
    
                    case 3:
                            dHour=7;
                            dMin=30;
                            fNum="USC 900";
                            aHour=9;
                            aMin=30;
                            durHour=9;
                            durMin=0;
                            aircraft="Boeing 777";
                            max_seat_rows=30;
                            max_seat_cols=10;
                    break;
            }
    
    
                    details(fNum,dHour,dMin,aHour,aMin, aircraft);
    //This section declares everything in all of the arrays to 0;
    
    
                     for(int a=0;a<max_seat_rows;a++)
                     {
                            for(int b=0;b<max_seat_cols;b++)
                            {
                                    cout<<seats[a][b]<<"\t";
    
                            }
                            cout<<endl;
    
                     }
    
    // This section determines how many empty seats there are
    
                     for(int c=0;c<max_seat_rows;c++)
                     {
                            for(int d=0;d<max_seat_cols;d++)
                            {
                                    if (seats[c][d]==0)
                                    empty++;
    
                            }
                     }
    
                            cout<<"There are "<<empty<<" empty seats"<<endl;
    //This section takes the amount of seats that the user wishes to reserve and makes them unavailable
    
    
                            cout<<"How many seats would you like to reserve?"<<endl;
                            cin>>resAmt;
    
                            for (int e=0;e>resAmt;e++)
                            {
    
                                            for(int c=0;c<max_seat_rows;c++)
                                            {
                                                    for(int d=0;d<max_seat_cols;d++)
                                                    {
                                                            if (seats[c][d]==0)
                                                            {
                                                            seats[c][d]=1;
                                                            }
                                                            else
                                                            {
                                                            cout<<"This seat is already taken"<<endl;
                                                            }
    
                                                    }
                                            }
    
    
                            }
    
    return 0;
    
    
    }
    
    
                   void details( string fNum,int dHour,int dMin,int aHour,int aMin, string aircraft)
    {
                    cout<<"\n\nYou Have Chosen to Fly on Flight Number "<<fNum<<endl;
                    cout<<"The Flight will Depart at "<<dHour<<":"<<dMin<<endl;
                    cout<<"The Flight will Arrive at its Destination in "<<aHour<<" Hours and "<<aMin<<" Minutes"<<endl;
                    cout<<"Aircraft is the "<<aircraft<<endl;
    
    }
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    In this declaration
    int seats[max_seat_rows][max_seat_cols]={0};

    what is value of max_seat_rows and max_seat_cols

    If you want to set the size dynamically then decalre a double pointer array and initialize it.

    Raghu

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Read this



      before you start working with arrays.

      Comment

      Working...