If you have a look at thise code, how could I terminate the program as mentioned in the example?
As always, help is appreciated.Code:#include <iostream> using std::cout; using std::cin; // Prototypes void firstClass( int [], int ); void economyClass( int [], int ); void boardingPass( int, int ); int main() { const int numberSeats = 9; int airlineSeats[ numberSeats ] = { 0 }; int choice = 0; do { cout << "\nPress 1 for \"First Class\"" << "\nPress 2 for \"Economy Class\"" << "\nPress 3 to Quit" << "\n\nEnter your choice: "; cin >> choice; switch( choice ) { case 1: firstClass( airlineSeats, numberSeats ); break; case 2: economyClass( airlineSeats, numberSeats ); break; case 3: return 0; break; default: cout << "Woops! Try again.\n"; } } while( choice != 3 ); cin.get(); return 0; } void firstClass( int seat[], int size ) { static int placeFirst = 0; const int type = 1; char otherTicket; if( placeFirst > size - 5 ) { cout << "\nFirst Class is unfortunately fully booked!\n" << "Would you like an \"Economy Class\" ticket? [y/n] "; cin >> otherTicket; if( otherTicket == 'y' ) economyClass( seat, size ); else cout << "\nNext flight leaves in 3 hours."; I want the program to terminate here } else { seat[ placeFirst ] = 1; ++placeFirst; boardingPass( type, placeFirst ); } } void economyClass( int seat[], int size ) { static int placeEcon = 5; const int type = 2; char otherTicket; if( placeEcon > size ) { cout << "\nEconomy Class is unfortunately fully booked!\n" << "Would you like a \"First Class\" ticket? [y/n] "; cin >> otherTicket; if( otherTicket == 'y' ) firstClass( seat, size ); else cout << "\nNext flight leaves in 3 hours."; I want the program to terminate here } else { seat[ placeEcon ] = 1; ++placeEcon; boardingPass( type, placeEcon ); } } void boardingPass( int firstSecond, int seating ) { cout << "\n**************************" << "\nBOARDING PASS" << "\n\n"; if( firstSecond == 1 ) cout << "First Class\n"; else cout << "Economy Class\n"; cout << "Seat number: " << seating << "\n**************************\n"; }



LinkBack URL
About LinkBacks


