0 errors but no output.. any advice??

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

    0 errors but no output.. any advice??

    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 = 10;
       char a = 0;
       char w = 0;
      
      int total_passenger = 12;
      
      int arr1[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
      int arr2[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
      int arr3[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
      int arr4[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
      int arr5[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
      int arr6[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
      int arr7[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
      int arr8[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
      int arr9[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
      int arr10[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
      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)
                    {
                        strcmp(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 < 200; i++)
        {
            for(int j = 0; j < 2; j++)
                SeatArray[i][j].Available = 1;
        }
    }
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Hi,
    You have defined the SeatArray like this struct Seat SeatArray[10][20];
    and you are initializing it till 200...How it will work and this will surely crash.

    thanks
    Raghu

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      My guess is that when you run the program you immediately enter menu option 5 and exit it and it correctly prints nothing.


      OK a bit facetious but my point is that you have made no attempt to describe what you entered into the program and what you expected the program to do. All you have done is given the result and that result is actually valid for given program inputs.

      Please describe the problem in more detail.

      Comment

      Working...