I'll type the assignment I've been given. Then I'll tell you what my problem is, then I'll post my code. I'm sure the answer is probably so freaking stupid and would bite me if it had teeth. :mrgreen:
A small airline has just purchased a computer for its new automated reservations system. You have been asked to program the new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats).
Your program should display the following menu of alternatives - Please type 1 for "First Class" and Please type 2 for "Economy". If the person types 1, your program should assign a seat in the first class section (seats 1-5). If the person types 2, your program should assign a seat in the economy section (seats 6-10). Your program should print a boarding pass indicating the person's seat number and whether it is the first class or economy section of the plane.
Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available.
Your program should, of course, never assign a seat that has already been assigned. When the first class section is full, your program should ask the person if it is acceptable to be placed in the economy section (and vice versa). If yes, then make the appropriate seat assignment. If no, then print the message "Next flight leaves in 3 hours."
Here is what I can't figure out. I can't seem to figure out how to loop back to where the customer can input what seat type they want again once a seat has been allowed. That's the only way that it will ever fill more than just one seat. Also, I don't know how I'd print a boarding pass. Can someone please help? Here's what I have so far: (Somehow it has no errors. That's good, right?) :D
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int Seats [ 10 ] = { 0 };
int First_Class = 1;
int Economy = 1;
int Customer_Input;
char Yes_No;
for (int i = 1; i < 10; i++ )
{
cout << endl;
cout << "Please type 1 for \"First Class\"" << endl;
cout << "Please type 2 for \"Economy\"" << endl;
cin >> Customer_Input;
if ( Customer_Input == 1 ) {
if ( First_Class << 5 ){
cout << "Your First Class seat is: " << First_Class << endl;
First_Class++;
}
else if ( First_Class >= 5 ) {
cout << "The First Class section is full.\n"
<< "Would you like to sit in the Economy Section?\n"
<< "Press 1 for yes, 2 for no.";
cin >> Yes_No;
if ( Yes_No == 2 ) {
cout << "Next flight leaves in 3 hours." << endl;
}
else if ( Yes_No == 1 ) {
if ( Economy << 10 ) {
cout << "Your Economy seat is: " << Economy << endl;
Economy++;
}
else if ( Economy >= 10 ) {
cout << "The Economy section is also full.\n"
<< "Next flight leaves in 3 hours." << endl;
}}}}
if ( Customer_Input == 2 ) {
if ( Economy << 10 ) {
cout << "Your Economy seat is: " << Economy << endl;
Economy++;
}
else if ( Economy >= 10 ) {
cout << "The Economy section is full.\n"
<< "Would you like to sit in the First Class Section?\n"
<< "Type 1 for yes, 2 for no.";
cin >> Yes_No;
if ( Yes_No == 2 ) {
cout << "Next flight leaves in 3 hours." << endl;
}
else if ( Yes_No == 1 ) {
if ( First_Class << 5 ) {
cout << "Your First Class seat is: " << First_Class << endl;
First_Class++;
}
else if ( First_Class >= 5 ) {
cout << "The First Class section is also full.\n"
<< "Next flight leaves in 3 hours." << endl;
}}}}
return 0;
}}