1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include <iostream>
#include <string>
using namespace std;
int main ()
{
int spotstaken = 0;
int verticalindex;
int acrossindex;
int row;
char seat;
char again;
string plane [7][4] = {{"1A","1B","1C","1D"}, //creates a 2 dimensional table array and sets a value to each spot on the table
{"2A","2B","2C","2D"}, //It's set up in a square like this just to make it easier to recognize what's what on the table- just more organized
{"3A","3B","3C","3D"},
{"4A","4B","4C","4D"},
{"5A","5B","5C","5D"},
{"6A","6B","6C","6D"},
{"7A","7B","7C","7D"}};
do
{
for (int x = 0; x < 7; x++) //A for loop for displaying the table created above to the user. So long as x is less than 7 it will continue to display, same for y being less than 4.
{
for (int y = 0; y < 4; y++)
{
cout << plane [x][y] << " " ; //the for loops enable all the x and y variables created above to be outputted at once to the user
}
cout << endl;
}
cout << "Above is the seating chart to an airplane." << endl;
cout << "Type in the row of the seat you want. (EX: 1)" << endl;
cin >> row;
verticalindex = row - 1;
if (verticalindex > 6 || verticalindex < 0)
{
spotstaken = spotstaken;
cout << "Sorry, you must have typed something wrong. Try again?" << endl;
cout << "Type 'y' or 'Y' to continue, or 'n' or 'N' to quit." << endl;
cin >> again;
}
cout << "Now type in the letter of the seat you want. (EX: A)" << endl;
cin >> seat;
if (seat == 'a' || seat == 'A')
acrossindex = 0;
else if (seat == 'b' || seat == 'B')
acrossindex = 1;
else if (seat == 'c' || seat == 'C')
acrossindex = 2;
else if (seat == 'd' || seat == 'D')
acrossindex = 3;
else
{
cout << "Sorry, you must have typed something wrong. Try again?" << endl;
cout << "Type 'y' or 'Y' to continue, or 'n' or 'N' to quit." << endl;
cin >> again;
}
if (plane [verticalindex][acrossindex] == "X")
{
cout << "Sorry, that seat is already taken. Do you want to try again?" << endl;
cout << "Type 'y' or 'Y' to continue, or 'n' or 'N' to quit." << endl;
cin >> again;
}
else if (plane [verticalindex][acrossindex] != "X")
{
cout << "Okay, your seat will be filled in the chart." << endl;
plane [verticalindex][acrossindex] = 'X';
spotstaken = spotstaken + 1;
if (spotstaken < 28)
{
cout << "Would you like to contine filling in seats?" << endl;
cout << "Type 'y' or 'Y' to continue, or 'n' or 'N' to quit." << endl;
cin >> again;
}
else //this is the added part of the code. Not sure why it makes a difference, but it works!
again = 'n';
}
} while (again == 'y' || again == 'Y' && spotstaken != 28 );
if (spotstaken == 28)
{
cout << "The plane is now full!" << endl;
for (int x = 0; x < 7; x++)
{
for (int y = 0; y < 4; y++)
{
cout << plane [x][y] << " " ;
}
cout << endl;
}
}
system ("pause");
return 0;
}
|