I'm having a little trouble with this code. I've been assigned to make an Airline Reservations System script. Here's what I have to do:
There's a 10 element array, and that represents the seating chart on the plane. All elements are set to 0. When a person takes a seat, that element is substituted with a 1 to declare that the seat has been filled. There are two seating sections: First Class and Economy. A person can decide what section they want their seat in. If First Class has been completely filled, then the program asks if it should assign a seat to the Economy. If yes, then a seat in Economy gets filled. If no, a message is displayed.
Here's what I have so far:
Code:
#include <iostream.h>
#include <windows.h>
int main (int argc, char *argv[])
{
// Define the input values
string economy_input;
int input;
int counter = 0;
// Define the arrays
int firstclass[5] = {0, 0, 0, 0, 0};
int economy[5] = {0, 0, 0, 0, 0};
while (counter != -1)
{
for (int i = 0; i < sizeof(firstclass); i++)
{
cout << "Please type in 1 for \"First Class\" or 2 for \"Economy\"" << endl;
cin >> input;
if (input == 1) // "First Class" has been entered
{
if (firstclass[i] == 0 && firstclass[i] <= sizeof(firstclass)) // Checks to make sure that there is a spot left in the array
{
firstclass[i] = 1; // Fill in the element
cout << "Assigning the person's seat to: " << i << " in the first class section." << endl;
}
else
{
cout << "All of the first class spaces have been filled. Would you like to go to economy? Yes or No" << endl;
getline(cin,economy_input);
if (economy_input == "No")
{
cout << "Next flight leaves in 3 hours." << endl;
}
if (economy_input == "Yes")
{
if (economy[i] == 0 && economy[i] <= sizeof(economy))
{
economy[i] = 1;
cout << "Assigning the person's seat to: " << i << endl;
}
}
}
}
if (input == 2) // "Economy" has been entered
{
for (int i = 0; i < sizeof(economy); i++)
{
if (economy[i] == 0 && economy[i] <= sizeof(economy))
{
economy[i] = 1;
cout << "Assigning the person's seat to: " << i << " in the economy section." << endl;
}
}
}
}
return 0;
}
I'm not sure how the for loops and while loop would work for this script. I don't even know if there are suppose to be for loops/while loops. If someone could help me fix this up, it would be much appreciated.