#include <cstdlib>
#include <iostream>
#include <string.h>
#include <cstdlib>



using namespace std;

int main(int argc, char *argv[])
{
    int airp[13][6], row[2];
    string t;
    char airc[13][6], s;

    for(int i = 0; i < 13; ++i)
    {
            for (int z = 0; z < 6 ;++z)
            {
                airc[i][z] = '*';
                airp[i][z] = 0;


                }
            }

    for (;;)
    {
        cout<<"Rows #1 thru #2 are First  (F) class\n";
        cout<<"Rows #1 thru #7 are business (B) class\n";
        cout<<"Rows 8 thru 13 are economy (E) class \n";
        cout<<"* Means the seat is Available\n";
        cout<<"X meas the seat is Occupies\n";
        cout<<"    \tA\tB\tC\tD\tE\tF\n";
        cout<<"Row 1\t"<<airc[0][0]<<"\t"<<airc[0][1]<<"\t"<<airc[0][2]<<"\t"<<airc[0][3]<<"\t"<<airc[0][4]<<"\t"<<airc[0][5]<<"\n";
        cout<<"Row 2\t"<<airc[1][0]<<"\t"<<airc[1][1]<<"\t"<<airc[1][2]<<"\t"<<airc[1][3]<<"\t"<<airc[1][4]<<"\t"<<airc[1][5]<<"\n";
        cout<<"Row 3\t"<<airc[2][0]<<"\t"<<airc[2][1]<<"\t"<<airc[2][2]<<"\t"<<airc[2][3]<<"\t"<<airc[2][4]<<"\t"<<airc[2][5]<<"\n";
        cout<<"Row 4\t"<<airc[3][0]<<"\t"<<airc[3][1]<<"\t"<<airc[3][2]<<"\t"<<airc[3][3]<<"\t"<<airc[3][4]<<"\t"<<airc[3][5]<<"\n";
        cout<<"Row 5\t"<<airc[4][0]<<"\t"<<airc[4][1]<<"\t"<<airc[4][2]<<"\t"<<airc[4][3]<<"\t"<<airc[4][4]<<"\t"<<airc[4][5]<<"\n";
        cout<<"Row 6\t"<<airc[5][0]<<"\t"<<airc[5][1]<<"\t"<<airc[5][2]<<"\t"<<airc[5][3]<<"\t"<<airc[5][4]<<"\t"<<airc[5][5]<<"\n";
        cout<<"Row 7\t"<<airc[6][0]<<"\t"<<airc[6][1]<<"\t"<<airc[6][2]<<"\t"<<airc[6][3]<<"\t"<<airc[6][4]<<"\t"<<airc[6][5]<<"\n";
        cout<<"Row 8\t"<<airc[7][0]<<"\t"<<airc[7][1]<<"\t"<<airc[7][2]<<"\t"<<airc[7][3]<<"\t"<<airc[7][4]<<"\t"<<airc[7][5]<<"\n";
        cout<<"Row 9\t"<<airc[8][0]<<"\t"<<airc[9][1]<<"\t"<<airc[8][2]<<"\t"<<airc[8][3]<<"\t"<<airc[8][4]<<"\t"<<airc[8][5]<<"\n";
        cout<<"Row 10\t"<<airc[9][0]<<"\t"<<airc[9][1]<<"\t"<<airc[9][2]<<"\t"<<airc[9][3]<<"\t"<<airc[9][4]<<"\t"<<airc[9][5]<<"\n";
        cout<<"Row 11\t"<<airc[10][0]<<"\t"<<airc[10][1]<<"\t"<<airc[10][2]<<"\t"<<airc[10][3]<<"\t"<<airc[10][4]<<"\t"<<airc[10][5]<<"\n";
        cout<<"Row 12\t"<<airc[11][0]<<"\t"<<airc[11][1]<<"\t"<<airc[11][2]<<"\t"<<airc[11][3]<<"\t"<<airc[11][4]<<"\t"<<airc[11][5]<<"\n";
        cout<<"Row 13\t"<<airc[12][0]<<"\t"<<airc[12][1]<<"\t"<<airc[12][2]<<"\t"<<airc[12][3]<<"\t"<<airc[12][4]<<"\t"<<airc[12][5]<<"\n\n";

        cout<<"Please enter the ticket type:F,B,or E: ";
        cin>>t;

        cout<<"Please Enter The Desired Row: ";
    cin>>row[0];

    cout<<"Please Enter The Desired Seat (A,B,C,D,E or F): ";
    cin>>s;



    switch(s)
    {
        case 'A':
        case 'a':
            row[0] = row[0] - 1;
            row[1] = 1;
            row[1] = row[1] - 1;
        break;

        case 'B':
        case 'b':
            row[0] = row[0] - 1;
           row[1] = 2;
            row[1] = row[1] - 1;
        break;

        case 'C':
        case 'c':
            row[0] = row[0] - 1;
           row[1] = 3;
            row[1] = row[1] - 1;
        break;

        case 'D':
        case 'd':
            row[0] = row[0] - 1;
           row[1] = 4;
            row[1] = row[1] - 1;
        break;

        case 'E':
        case 'e':
            row[0] = row[0] - 1;
         row[1] = 5;
            row[1] = row[1] - 1;
        break;

        case 'F':
        case 'f':
            row[0] = row[0] - 1;
            row[1] = 6;
            row[1] = row[1] - 1;
        break;

    }


    if(t == "F")
    {
        if(row[0]+1 == 1 || row[0]+1 == 2)
        {

        if(airp[row[0]][row[1]] == 0)
        {
           airp[row[0]][row[1]] = 1;
           airc[row[0]][row[1]] = 'X';
        }
        else if(airp[row[0]][row[1]] == 1)
        {
            cout<<"Message: Seat "<<row[0] + 1<<s<<" is already occupied"<<endl;
            system("Pause");
        }

        }
        else
        {
            cout<<"The desired seat is not in this class"<<endl;
            system("Pause");
                system("cls");
            continue;   
        }

    }
    else if(t == "B")
    {
        if(row[0]+1 == 3 || row[0]+1 == 4 || row[0]+1 == 5 
                || row[0]+1 == 6|| row[0]+1 == 7)
        {
        if(airp[row[0]][row[1]] == 0)
        {
           airp[row[0]][row[1]] = 1;
           airc[row[0]][row[1]] = 'X';
        }
        else if(airp[row[0]][row[1]] == 1)
        {
            cout<<"Message: Seat "<<row[0] + 1<<s<<" is already occupied"<<endl;
            system("Pause");
        }
        }
        else
        {
            cout<<"The desired seat is not in this class"<<endl;
            system("Pause");
                system("cls");
            continue;   
        }
    }
    else if(t == "E")
    {
        if(row[0]+1 == 8 || row[0]+1 == 9 || row[0]+1 == 10 
                 || row[0]+1 == 11|| row[0]+1 == 12|| row[0]+1 == 13)
        {
        if(airp[row[0]][row[1]] == 0)
        {
           airp[row[0]][row[1]] = 1;
           airc[row[0]][row[1]] = 'X';
        }
        else if(airp[row[0]][row[1]] == 1)
        {
            cout<<"Message: Seat "<<row[0] + 1<<s<<" is already occupied"<<endl;
            system("Pause");
        }
        }
            else
        {
            cout<<"The desired seat is not in this class"<<endl;
            system("Pause");
                system("cls");
            continue;   
        }
}

      row[0] = 0;
      row[1] = 0;
    system("cls");
}

I have been stuck for hours, could someone please help me? No matter what I do I cant get it to stop looping. Thanks.

Recommended Answers

All 2 Replies

for (;;)

This will loop until you break; from it. So break; at the top level of the loop (i.e. not from within something else inside the for loop) where you want to stop looping.

commented: Thank you! +0

Hi, you can do something like this:

//...

cout<<"Do you want to continue (Y/N): ";
        cin>>t;
if (t == "Y" || t == "y") break; // Or any other way to get out of the f(;;) loop like exit();

cout<<"Please enter the ticket type:F,B,or E: ";
        cin>>t;

//...
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.