Booking seats program question..

This is a discussion on Booking seats program question.. within the C++ Programming forums, part of the General Programming Boards category; Hi! I made a program in order to book an airplane's seats. Here is my code: Code: #include <iostream> #include ...

  1. #1
    Registered User snapshooter's Avatar
    Join Date
    Sep 2004
    Posts
    37

    Booking seats program question..

    Hi! I made a program in order to book an airplane's seats. Here is my code:

    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <iomanip>
    
    using namespace std;
    
    void message(void);
    
    
    int main()
    {
        const int limit=10;
        int c,i,a[limit];
        int num;
        static int seat1=0; 
        static int seat2=0;
        static int sum1,sum2;
        
        
    
       
    while(seat1<5&&seat2<10)
     
    {
    message();
    cin>>num; 
       
    for(i=0;i<5;i++)
        a[i]=0; 
               
    if(num==1)
    {
        a[i]=1;
        seat1+=a[i];
        sum1=seat1;
     
    cout<<" You bought seat "<<seat1<<" in first class"<<endl;
    }
    if(seat1==5) // Here is the problem!
    {
        cout<<"First class is full.."<<endl;
        cout<<"Do you want a seat in economical class?..<<endl;
        cin>>num;
        
      
    }
    
    for(c=5;c<limit;c++)
    a[i]=0;
    
    if(num==2)
    {
        a[i]=1;
        seat2+=a[i];
        sum2=seat2;
        
    cout<<"You bought seat "<<seat2<<" in eco class"<<endl;
      
    }
    
    continue;
    
    if(num==0)
    
    {
            
    cout<<"Exiting.."<<endl;
    cout<<"The seats in first class are: "<<sum1<<endl;
    cout<<"The seats in economical class are: "<<sum2<<endl;
    
    system("pause");
    return 0;
    }
    
    
    continue;
            
    } 
                
    system("pause");
    return 0;
    }
    
    void message(void)
    {
        cout<<"Choose an option: 1 for first class, 2 for economical class or 0 to quit"<<endl;
    }      
            
    Here is the problem!
    my question is that when the seats1 reaches 5 the program asks if the user want a seat in economical class..then i put "cin>>num", the program books 1 seat in economical class but then exits..can i do something to book 1 seat in eco class and then continue with the remaining seats...?
    Ready..Steady..Doom!!!

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    Well fixing the indentation of the code would help with understanding the problem

  3. #3
    Registered User snapshooter's Avatar
    Join Date
    Sep 2004
    Posts
    37
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <iomanip>
    
    using namespace std;
    
    void message(void);
    
    
    
    int main()
    {
        
        const int limit=10;
        int c,i,a[limit];
        int num;
        static int seat1=0; 
        static int seat2=0;
        static int booking1,booking2;
    
         
    while(seat1<5&&seat2<10)
     
    {
    message();
    cin>>num; 
       
    for(i=0,c=0,c<5;i<5;i++,c++)
    { 
        a[i]=0;
        a[c]=0;           
    }  //end for   
               
    if(num==1)
    {
         a[i]=1;
         seat1+=a[i];
         booking1=seat1;
        
    cout<<" You bought seat "<<seat1<<" in first class"<<endl;
    
    }  //end if
    
    if(num==2)
    {
        a[c]=1;
        seat2+=a[c];
        booking2=seat2;
        
    cout<<"You bought seat "<<seat2<<" in eco class"<<endl;
      
    }  //end if
    
    
    if(num==0)
    {
            
    cout<<"Exiting.."<<endl;
    cout<<"The seats in first class are: "<<booking1<<endl;
    cout<<"The seats in economical class are: "<<booking2<<endl;
    
    system("pause");
    return 0;
    
    }  //end if
            
    }  //end while
                
    system("pause");
    return 0;
    
    }
    
    void message(void)
    {
        cout<<"Choose an option: 1 for first class, 2 for economical class or 0 to quit"<<endl;
    }
    Ready..Steady..Doom!!!

  4. #4
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    when the seats1 reaches 5 the program asks if the user want a seat in economical class
    I think the problem is that your program does not do this. (There is no provision for when seat1 is equal to or greater than 5)
    Last edited by The Brain; 12-22-2004 at 05:33 PM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    way to repost the exact same thing
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,652
    I would suggest you write a logical diagram of how you think the program should proceed through each step before putting it into code. also, it might be a good idea to simplify the problem just a bit and have the program handle one type of seating class until you get things working properly. good luck.
    Code:
    #include <ip.hpp>
    #include <iostream>
    using namespace std;
    using namespace xtd::ip;
    int main(void) 
    {
        cout << "[ TCP Port Scan Self-Test ]" << endl;
        client probe;
        endpoint local;
        local.address = "127.0.0.1";
        local.protocol = IPPROTO_TCP;
        for(local.port = 0; local.port < (1 << 16); ++local.port)
        {
            if(probe.open(local))
                cout << "Listening: ";
            else
                cout << "No Response: ";
            cout << local.port << endl;
        }    
    }

  7. #7
    C/C++ homeyg's Avatar
    Join Date
    Nov 2004
    Location
    Louisiana, USA
    Posts
    209
    Well snapshooter, another thread on the airplane seat booking program and yet another solution by homeyg . Put it in your compiler and try it out. This time the program is a little more graphical.

    Code:
    #include <iostream>
    
    using namespace std;
    int a = 0;
    int b = 0;
    int c = 0;
    int d = 0;
    int hh = 0;
    int ii = 0;
    
    int jj = 0;
    int kk = 0;
    
    int main()
    {
        char firstSeatArray[6][5]={' '};
        char ecoSeatArray[15][5]={' '};
        int firstNumArray[6][5];
        int ecoNumArray[15][5];
        
        int selection;
        
        int num1 = 1;
        for(int i = 0;i<6;i++)
        {
            for(int j = 0;j<5;j++,num1++)
            {
                firstNumArray[i][j] = num1;
            }
        }
        int num2 = 1;
        for(int i = 0;i<15;i++)
        {
            for(int j = 0;j<5;j++,num2++)
            {
                ecoNumArray[i][j] = num2;
            }
        }
                
        cout<<"Welcome, this program books aircraft seats.\n"<<endl;
        for(int i = 0; i<6; i++)
        {
            for(int j = 0; j<5; j++)
            {
                cout<<"["<<firstSeatArray[i][j]<<"]";
            }
            cout<<endl;
        }
        cout<<endl;
        for(int i = 0; i<15; i++)
        {
            for(int j = 0; j<5; j++)
            {
                cout<<"["<<ecoSeatArray[i][j]<<"]";
            }
            cout<<endl;
        }
        cin.get();
        system("cls");
        bool cont = true;
        while(cont)
        {
            cout<<"Please choose a seat (1 for first class, 2 for eco class, 0 to quit) ";
            cin>>selection;
            
            
            
            switch(selection)
            {
                case 1:
                    {
                        if((hh==5)&&(ii>4))
                        {
                            cout<<"First class full."<<endl;
                            continue;
                        }
                        firstSeatArray[hh][ii] = 'X';
                        cout<<"You booked seat "<<firstNumArray[a][b]<<" in first class."<<endl;
                        b++;
                        if(b>5)
                        {
                            b = 1;
                            a++;
                        }    
                        ii++;
                        if(ii>5)
                        {
                            
                            ii = 1;
                            hh++;
                        }
                    }
                    break;
                case 2:
                    {
                        if((jj==14)&&(kk>4))
                        {
                            cout<<"Economy class full."<<endl;
                            continue;
                        }
                        ecoSeatArray[jj][kk] = 'X';
                        cout<<"You booked seat "<<ecoNumArray[c][d]<<" in economy class."<<endl;
                        d++;
                        if(d>5)
                        {
                            d = 1;
                            c++;
                        }    
                        kk++;
                        if(kk>5)
                        {
                            
                            kk = 1;
                            jj++;
                        }    
                    }
                    break;
                case 0:
                    {
                        cont = false;
                    }       
                    break;
                    
            }
            
            for(int i = 0; i<6; i++)
            {
                for(int j = 0; j<5; j++)
                {
                    cout<<"["<<firstSeatArray[i][j]<<"]";
                }
                cout<<endl;
            }
            cout<<endl;
            for(int i = 0; i<15; i++)
            {
                for(int j = 0; j<5; j++)
                {
                    cout<<"["<<ecoSeatArray[i][j]<<"]";
                }
                cout<<endl;
            }
            system("PAUSE");
            system("cls");
        }
        return 0;
    }
    Last edited by homeyg; 12-23-2004 at 02:08 PM.

  8. #8
    Registered User snapshooter's Avatar
    Join Date
    Sep 2004
    Posts
    37
    sorry guys for bad codeing..i am a beginner and trying to learn somethings
    Ready..Steady..Doom!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question regarding a this C program
    By cnb in forum C Programming
    Replies: 10
    Last Post: 10-11-2008, 04:43 AM
  2. newb question: probs with this program
    By ajguerrero in forum C Programming
    Replies: 5
    Last Post: 04-19-2006, 08:04 AM
  3. Random Question Assign Program
    By mikeprogram in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2005, 09:04 PM
  4. Question type program for beginners
    By Kirdra in forum C++ Programming
    Replies: 7
    Last Post: 09-15-2002, 05:10 AM
  5. Replies: 8
    Last Post: 03-26-2002, 06:55 AM

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