# just need a little help

• 12-05-2001
edshaft
just need a little help
I amm writing a program where a plane has ten seats 5 r 1st class and the other 5 r economy and when all the seats in one category is full u ask if it is alright to place them in the other and well im having alittle trouble:

int first(int seat[], int i){
int non;
if(seat[4]!=1){
seat[i]=1;
cout<<"You are in seat "<<i+1<<" in first class\n";
}
else {
cout<<"Is it all right to place you in nonsmoking?(y/n)\n";
cin>> non;
if(non=='y'||'Y'){
int j=5;
int econ(seat,j);}
else{
cout<<"Next flight in three hours\n";}}
return 0;
}
int econ(int seat[], int j){
int non;
if(seat[9]!=1){
seat[j]=1;
cout<<"You are in seat "<<j-4<<" in economy\n";
}
else {
cout<<"Is it all right to place you in smoking?(y/n)";
cin>> non;
if(non=='y'||'Y'){
int i=0;
int first(seat,i);}
else{
cout<<"Next flight leaves in three hours.";}}
return 0;
}
int main(int argc, char* argv[])
{int seat[10], assign, i=0, j=5;
while(seat[10]!=1){
cout<<"Please type 1 for First Class\n";
cin>>assign;
if (assign==1){
first(seat,i);
i++;}
else{econ(seat,j);
j++;}
}
return 0;
}
• 12-05-2001
Prelude
Assumng that your user will always enter the proper input (will never happen, so this is purely academic).
Code:

```int main(){     int firstClass = 1, coach = 6;     puts("Please enter your section (f = first class, c = coach)");     if(getchar() == 'f'){         if(firstClass != 6){             printf("You are in seat %d", firstClass++);         }else{             puts("First class is full, will you ride coach? (y/n)");             if(getchar() == 'y')                 if(coach == 11) printf("Sorry, you've been bumped");                 else printf("You are in seat %d", coach++);             else printf("I'm sorry, you're screwed");         }     }else{         if(coach != 11){             printf("You are in seat %d", coach++);         }else{             puts("Coach is full, will you ride first class? (y/n)");             if(getchar() == 'y')                 if(firstClass == 6) printf("Sorry, you've been bumped");                 else printf("You are in seat %d", firstClass++);             else printf("I'm sorry, you're screwed");         }     }     return 0; }```
Throw this in a loop and you will be all set.

-Prelude
• 12-08-2001
edshaft
thanx but that is not what i want im usind microsofr visual c++ and well i have my code just about where i want it but when it runs out of room in 1st and i say n to being put in econ it puts me there anyway and when i say n in econ i get an infinte loop here's the code:
int first(int [], int);
int econ(int [],int);
int main(int argc, char* argv[])
{int seat[5], seats[5], assign, i=0, j=0;
while(seat[11]!=0){
cout<<"Please type 1 for First Class\n";
cin>>assign;
if (assign==1){
first(seat,i);
i++;}
else{econ(seats,j);
j++;}
}
return 0;
}
int first(int seat[], int i){
char non;
if(seat[4]!=1){
seat[i]=1;
cout<<"You are in seat "<<i+1<<" in first class\n";
}
else {
cout<<"Is it all right to place you in nonsmoking?(y/n)\n"<<flush;
cin>> non;
if(non=='y'||'Y'){
int i=0;
int seats[5];
econ(seats,i);}
else{
cout<<"Next flight in three hours\n";}}
return 0;
}
int econ(int seat[], int j){
int non;
if(seat[4]!=1){
seat[j]=1;
cout<<"You are in seat "<<j+1<<" in economy\n";
}
else {
cout<<"Is it all right to place you in smoking?(y/n)"<<flush;
cin>> non;
if(non=='y'||'Y'){
int i=0;
first(seat,i);}
else
cout<<"Next flight leaves in three hours.";}
return 0;
}:confused:
Quote: