How to move around inside For Loop; Please help

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

#include <iostream>
#include<iomanip>

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<seats; i++)// simple for loop initialising all array elements to false
		SeatingPlan[i] = false;
	do
	{ // do loop makes a recuring menu
		count ++ ;
cout<< " Reservations" << endl;
cout <<"--------------"<<endl;
cout<<"Please enter 1 for First Class bookings"<< endl;
cout<<"Please enter 2 for Economy bookings"<< endl;
cin>> choice;

//First Class Section
if (choice ==1)
	{
		cout<<"Welcome to First Class booking"<<endl;
	cout<<"------------------------------"<<endl;
	if ( f > 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"<<endl;
	cout<<"------------------------------"<<endl;
	if ( e > 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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include<iomanip>

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"<<endl;
	cout<<"------------------------------"<<endl;
	if ( f > 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"<<endl;
	cout<<"------------------------------"<<endl;
	if ( e > 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<seats; i++)// simple for loop initialising all array elements to false
		SeatingPlan[i] = false;
	do
	{ // do loop makes a recuring menu
		count ++ ;
              cout<< " Reservations" << endl;
              cout <<"--------------"<<endl;
              cout<<"Please enter 1 for First Class bookings"<< endl;
              cout<<"Please enter 2 for Economy bookings"<< endl;
              cin>> 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.