The Problem is on my 'int main( )' what do you suggest???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prakatak7410
    New Member
    • Dec 2009
    • 6

    The Problem is on my 'int main( )' what do you suggest???

    Code:
    #include <iostream>
    #include <cctype>
    #include <string>
    #include <cstring>
    using namespace std;
    
    
    int assignSeat(int seat_num, int row_num, int pass_num);
    int num1(char*);
    int num2(char*);
    
    int NumSeats = 200;
    
    void InitializeSeats();
    void Reserve();
    void Cancel();
    void ChangeSeat();
    void Display();
    
    struct Seat
      {
          char pass_name[80];
          int Available;
      };
      
      struct Seat SeatArray[10][20];
      
    int main()
    {      
       char seatchioce = 0;
       int row_num = 20;
       char a = 0;
       char w = 0;
      
      int total_passenger = 12;
      
      char arr1[][20] = {"1A","2A","3A","4A","5A","6A","7A","8A","9A", "10A","11A","12A","13A","14A","15A","16A","17A","18A","19A",""20A"};
      char arr2[][20] = {"1B","2B","3B","4B","5B","6B","7B","8B","9B", "10B","11B","12B","13B","14B","15B","16B","17B","18B","19B",""20B"};
      char arr3[][20] = {"1C","2C","3C","4C","5C","6C","7C","8C","9C", "10C","11C","12C","13C","14C","15C","16C","17C","18C","19C",""20C"};  
      char arr4[][20] = {"1D","2D","3D","4D","5D","6D","7D","8D","9D", "10D","11D","12D","13D","14D","15D","16D","17D","18D","19D",""20D"};  
      char arr5[][20] = {"1E","2E","3E","4E","5E","6E","7E","8E","9E", "10E","11E","12E","13E","14E","15E","16E","17E","18E","19E",""20E"}; 
      char arr6[][20] = {"1F","2F","3F","4F","5F","6F","7F","8F","9F", "10F","11F","12F","13F","14F","15F","16F","17F","18F","19F",""20F"};   
      char arr7[][20] = {"1G","2G","3G","4G","5G","6G","7G","8G","9G", "10G","11G","12G","13G","14G","15G","16G","17G","18G","19G",""20G"};  
      char arr8[][20] = {"1H","2H","3H","4H","5H","6H","7H","8H","9H", "10H","11H","12H","13H","14H","15H","16H","17H","18H","19H",""20H"};  
      char arr9[][20] = {"1I","2I","3I","4I","5I","6I","7I","8I","9I", "10I","11I","12I","13I","14I","15I","16I","17I","18I","19I",""20I"};  
      char arr10[][20] = {"1J","2J","3J","4J","5J","6J","7J","8J","9J", "10J","11J","12J","13J","14J","15J","16J","17J","18J","19J",""20J"};  
      int MenuChoice;
    
      InitializeSeats();
      while(1)
      {
          cout << " 1. Reserve" << endl;
          cout << " 2. Cancel" << endl;
          cout << " 3. Change Seat" << endl;
          cout << " 4. Display" << endl;
          cout << " 5. Exit" << endl;
    
          cout << "Enter your choice: ";
          cin >> MenuChoice;
    
        if((MenuChoice < 0) && (MenuChoice > 5))
        {
          cout << "Invalid Choice" << endl;
          system("Pause Try Again");
        }
        else
        {
            switch(MenuChoice)
            {
                case 1: Reserve();
                    break;
                case 2: Cancel();
                    break;
                case 3: ChangeSeat();
                    break;
                case 4: Display();
                    break;
                case 5:
                    exit(1);
            }
        }
        cin.get();  
      }
      
    return 0;
    
    }
    void Reserve() 
    {
        int pass_num = 0;
    
        cout << "Wellcome to Brofar Airline Passenger seat reservation" << endl;
            
         cout << "All " << NumSeats << " seats are available " << endl;
        
         for(int i = 0; i < 10; i++)
         {
             for(int j = 0; j < 20; j++)
             {
                 if(SeatArray[i][j].Available == 1)
                 {
                     cout << "Please enter the passenger name: ";
                     cin >> SeatArray[i][j].pass_name;
                     SeatArray[i][j].Available = 0;
                     NumSeats--;
                     return;
                 }
             }
            
         }
    }
    void Cancel()
    {
        char CancelPassengerName[80];
    
        cout << "Enter the Passenger to be cancelled: ";
        cin >> CancelPassengerName;
        for(int i =0; i <10; i++)
        {
            for(int j=0; j<20; j++)
            {
                
                if(strcmp(SeatArray[i][j].pass_name, CancelPassengerName) == 0)
                {
                    NumSeats++;
                    SeatArray[i][j].Available = 1;
                    return;
                }
            }
        }
        cout << " Passenger not in the list" << endl;
    }
    void ChangeSeat()
    {
        char MovePassenger[80];
        int SeatRow, SeatColumn;
    
        cout << "Enter the passenger name to be moved: ";
        cin >> MovePassenger;
    
        for(int i = 0; i < 10; i++)
        {    for(int j = 0; j < 20; j++)
            {
                if(strcmp(SeatArray[i][j].pass_name, MovePassenger) == 0)
                {
                    SeatRow = i;
                    SeatColumn = j;
                }
            }
        }
    
        if(NumSeats <= 0)
        {
            cout << "No seat available there for you cannot change seat" << endl;
            return;
        }
        else{
            for(int i = 0; i < 10; i++)
            {
                for(int j = 0; j < 20; j++)
                {
                    if(SeatArray[i][j].Available == 1)
                    {
                        strcpy_s(SeatArray[i][j].pass_name, MovePassenger);
                        SeatArray[SeatRow][SeatColumn].Available = 1;
                        SeatArray[i][j].Available = 0;
    
                        return;
                    }
                }
            }
        }
    }
    void Display()
    {
        for(int i = 0; i < 10; i++)
        {
            for(int j = 0; j < 20; j++)
            {
                if(SeatArray[i][j].Available == 0)
                {
                    cout << SeatArray[i][j].pass_name << " = " << i+1;
                                    if (j == 0) { cout << "A" << endl; }
                                    else { cout << "B" << endl; }
                }
                else
                {
                    if(j == 1)
                        cout << i+1 << "B" << endl;
                    else
                        cout << i+1 << "A" << endl;
                }
            }
        }
    }
    
    void InitializeSeats()//Initialy all seats are available
    {
        for(int i = 0; i < 30; i++)
        {
            for(int j = 0; j < 2; j++)
                SeatArray[i][j].Available = 1;
        }
    }
    Last edited by Frinavale; Dec 8 '09, 04:00 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • mac11
    Contributor
    • Apr 2007
    • 256

    #2
    What sort of help do you need? Are you trying to compile this code and get errors or does it compile but not do what you want?

    Comment

    • prakatak7410
      New Member
      • Dec 2009
      • 6

      #3
      i have already compiled it... but then i get 61 errors just on my int main... i dont get my problem there.. it says here...

      syntax error : 'bad suffix on number'
      syntax error : 'constant'
      newline in constant
      syntax error : missing ';' before '{'
      syntax error : 'bad suffix on number'
      syntax error : missing ';' before 'constant'
      newline in constant
      syntax error : missing ';' before identifier 'B'
      'B' : undeclared identifier
      syntax error : missing ';' before 'string'
      syntax error : missing ';' before type 'char'

      and so on and so forth....

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        I would double check the declaration of all your arrays first.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          In the future could you please only post the code that is relevant to the problem. It's unfair to expect people to sift through tons of code to find the few lines that you are having problems with.

          Also, in the future, please specify what you are having problems with, what (if any) errors you are getting, and what you have tried to solve the problem. Don't just post a bunch of code and expect us to figure out what it is, what's wrong with it, and what you are having problems with.

          Please check out the posting guidelines for more information on how to ask a question.

          You have a whole bunch of 2D arrays declared.
          Are you sure that you are doing this correctly?

          **edit: haha looks like RedSon beat me to it**

          -Frinny

          Comment

          • RedSon
            Recognized Expert Expert
            • Jan 2007
            • 4980

            #6
            I would also examine this line of code:

            struct Seat SeatArray[10][20];

            Further, feel free to post your error messages in their entirety.

            edit: Looks like frin and I are having edit wars! :P

            Comment

            Working...