Hello Everyone,
Firstly, this site as been invaluable to me in recent weeks, so thankyou very much. My problem is that I have a question asked inside a For Loop, one input means breaking out of the loop (break) which works fine, the Alternative input means jumping to a different location within the loop.

Its a booking program for a small airline, with 1 plane, in which the first 5 seats are first class and 6-10 are economy. the question is after one section if full weather the user would like to try the other section, any help to take a positive input to that question and move the user to the appropriate part of the code would be much appreciated.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103`` `````` #include #include using namespace std; const int seats =9;//const int for array number bool SeatingPlan[seats]; // declating boolean array int choice;// varialbe for menu selection int choice2;// variable for first class over flow int choice3;// varialbe for Economy overflow int count =0;// limits the number of recursions the program will go through int f =1;//seat counter for First Class int e =6;//seat counter for second class int main() { for (int i =0; i> choice; //First Class Section if (choice ==1) { cout<<"Welcome to First Class booking"< 5)// prevents seat 6 from being booked as first class { cout<< " Unfortunately there arent enough seats" << "left in First Class, press 1 try Economy" <<" or any other key for more information"<< endl; cin>> choice2 ; if (choice2 != 1) { cout<<"The next flight leaves in 3 hours"<< endl; break; } if (choice2 ==1) { // fill me with code!! } } else if (f <= 5) { SeatingPlan[f] = true; cout<<" You Are booked in Seat "<< f<< " in First Class"<< endl; f++; } } //Economy Section if (choice ==2) { cout<<"Welcome to Economy booking"< 10)// shows that Economy section runs from seat 6 to 10 { cout<< " Unfortunately there arent enough seats" << "left in Economy, Press 1 to try First Class" <<"or any other key for more information"<< endl; cin>> choice3 ; if (choice3 != 1) { cout<<"The next flight leaves in 3 hours"<< endl; break; } if (choice3 ==1) { // fill me with code!! } } else if (e <= 10) { SeatingPlan[e] = true; cout<<" You Are booked in Seat "<< e<< " in Economy"<< endl; e++; } } } while (count <= 10); return 0; }``````
You would just add to the seat count. So if `f` is first class and `e` is economy.. If they tried for economy and it was filled and they said to go for first class you would then add them into first class.

The ability to jump around code without using methods that most people try to avoid will require to start harnessing the true potential of C++ which is OOP.
You can put each part in a separate function and call it:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990`` ``````#include #include using namespace std; const int seats =9;//const int for array number bool SeatingPlan[seats]; // declating boolean array int choice;// varialbe for menu selection int choice2;// variable for first class over flow int choice3;// varialbe for Economy overflow int count =0;// limits the number of recursions the program will go through int f =1;//seat counter for First Class int e =6;//seat counter for second class void function1() { cout<<"Welcome to First Class booking"< 5)// prevents seat 6 from being booked as first class { cout<< " Unfortunately there arent enough seats" << "left in First Class, press 1 try Economy" <<" or any other key for more information"<< endl; cin>> choice2 ; if (choice2 != 1) { cout<<"The next flight leaves in 3 hours"<< endl; break; } if (choice2 ==1) function2(); } else if (f <= 5) { SeatingPlan[f] = true; cout<<" You Are booked in Seat "<< f<< " in First Class"<< endl; f++; } } void function2() { cout<<"Welcome to Economy booking"< 10)// shows that Economy section runs from seat 6 to 10 { cout<< " Unfortunately there arent enough seats" << "left in Economy, Press 1 to try First Class" <<"or any other key for more information"<< endl; cin>> choice3 ; if (choice3 != 1) { cout<<"The next flight leaves in 3 hours"<< endl; break; } if (choice3 ==1) function1(); } else if (e <= 10) { SeatingPlan[e] = true; cout<<" You Are booked in Seat "<< e<< " in Economy"<< endl; e++; } } } int main() { for (int i =0; i> choice; //First Class Section if (choice ==1) function1(); if(choice==2) function2(); } while (count <= 10); return 0; }``````
Thanks guys,

im gonna give both of those options a go and see how i get on.

Thankyou again
If you happen to continue reading, JewelCPP's code is more object oriented than your approach, and is definitely more flexible in it's options. If you like the sound of that, people take a look at some tutorials like http://www.cplusplus.com/doc/tutorial/functions/
Both of these Ideas worked perfectly, I'm going to go with the functions as i think its a better approach, Thank you very much you lovely people. Merry Christmas to you both
Topic archived. No new replies allowed.