#include <iostream>
#include <cstdlib>
usingnamespace std;
int main (){
constint seat=10;
int seats[seat]={0};
int first=1, economy=6, choice, j;
char k;
cout<<"[1] First Class"<<endl<<"[2] Economy"<<endl;
for(j=1; j<=10; j++){
do{
cout<<endl<<"Please Choose:";
cin>>choice;
}while(choice<1||choice>2);
if(choice==1){
cout<<"Seat Number:"<<first<<endl;
if(first!=6){
cout<<endl<<"BOARDING PASS:"<<endl;
cout<<"-------------"<<endl;
cout<<"Class: First Class"<<endl;
cout<<"Seat Number:"<<first<<endl;
cout<<"-------------"<<endl;
first++;
}
else{
cout<<endl<<"FIRST CLASS FULL"<<endl;
cout<<"Do you want to transfer to int the ECONOMY SECTION?[y/n]: ";
cin>>k;
if ((k=='Y'||k=='y')&&economy<=11){
cout<<endl<<"Seat Number:"<<economy;
cout<<endl<<"BOARDING PASS:"<<endl;
cout<<"-------------"<<endl;
cout<<"Class: Economy Class"<<endl;
cout<<"Seat Number:"<<economy<<endl;
cout<<"-------------"<<endl;
economy++;
}
elseif ((k=='Y'||k=='y')&&economy>=11){
cout<<endl<<"All seats are taken."<<endl;
cout<<"Next flight will be in THREE HOURS"<<endl<<endl;
}
else
cout<<"Next Flight will be in THREE HOURS"<<endl;
}
} //end first class
else{
cout<<"Seat Number:"<<economy<<endl;
if(economy!=11){
cout<<endl<<"BOARDING PASS:"<<endl;
cout<<"-------------"<<endl;
cout<<"Class: Economy Class"<<endl;
cout<<"Seat Number:"<<economy<<endl;
cout<<"-------------"<<endl;
economy++;
}
else{
cout<<endl<<"ECONOMY CLASS FULL"<<endl;
cout<<"Do you want to transfer to in the FIRST CLASS SECTION?[y/n]: ";
cin>>k;
if ((k=='Y'||k=='y')&&first<=6){
cout<<endl<<"Seat Number:"<<first;
cout<<endl<<"BOARDING PASS:"<<endl;
cout<<"-------------"<<endl;
cout<<"Class: First Class"<<endl;
cout<<"Seat Number:"<<first<<endl;
cout<<"-------------"<<endl;
first++;
}
elseif ((k=='Y'||k=='y')&&first>=6){
cout<<endl<<"All seats are taken."<<endl;
cout<<"Next flight will be in THREE HOURS"<<endl<<endl;
}
else
cout<<"Next Flight will be in THREE HOURS"<<endl;
}
}//end economy
}// end for
cout<<endl<<endl;
system("pause");
return 0;
}
Please be more exact because I don't really know what is the problem. If you have a problem with that array, don't initialize it. Instead of int seats[seat]={0}; put int seats[seat];. See if it works!
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
" F i r s t C l a s s " and P l e a s e 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 in 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 I to indicate that the seat is no longer available.