How to get this program to remember the seat

Hi guys (again), i am here with a new program! This time, i have created an airline reservation system that allows a user to choose a seat, the problem i having is, getting the program that this to remember that this seat has been booked, any tips on how to do this?

What im asking for is for the program to remember that if a seat is booked, for it to remember that it is booked. For example, if the user books seat 5, i want it to remember that ive booked seat 5 and to prompt me that its taken, its an array code that i dont knot, can anyone help me and where to put 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

#include<iostream>
using namespace std;
int main()
{
	int choice,i,position;
	bool firstclass[5] ={0};
	bool secondclass[10] ={0};
	char ch;
	int seats[10]={0};
	while(true)
	{
		cout<<"\t\tChoose your class\n";
		cout<<"\t1.First Class\n";
		cout<<"\t2.Second Class\t";
		cin>>choice;
		switch(choice)
		{
		case 1:
			cout<<"Seats available \n";
			for(i=1;i<=5;i++)
				if (firstclass [firstclass] == 0)
			{
				cout <<i<<" ";
			}
			cout<<"\nChoose your seat (1-5)\n";
			cin>>position;
			break;
			cout <<"\n Your seat number is:" << position << endl;
			
		case 2:
			cout<<"Seats available \n";
			for(i=5;i<=10;i++)
			{
				cout<<i<<" ";
			}
			cout<<"\nChoose your seats (6-10)\n";
			break;
		}
		cout<<"Wish to continue(Y/N)\n";
		cin>>ch;
		if(ch=='y' || ch=='Y') continue;
		if(ch=='n' || ch=='N') exit(0);
	}

    return 0;

}
Perhaps as each seat is taken, you could change its value from zero to one, and then when the user chooses a seat, if the value of that seat is one, it is taken, and they must choose another.
Last edited on
Yes, this makes sense! Do you know how i could do this?
I see you have an array called seats.

1
2
seat[0] = 0; // mark as empty
saet[4] = 1; // mark as taken 


You also have arrays called firstclass and secondclass. I suggest you decide just how it is that you're keeping track of seats and remove what you don't actually need.
Last edited on
I was going to keep track of the seats by simply displaying the array of class, for example, if the user chooses firstclass, it will show that seats : 1 2 3 4 5 are available, once a seat is taken, i want it to no longer display the seat that is taken.
Well then the logic will be something like:
1
2
3
4
FOR loop over each seat{
  IF (seat is available)
    { cout << seatNumber}
}
Ah okay, thank you so much, now to try and put this into codes!
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
#include<iostream>
using namespace std;
#define MAX 5
int main()
{
	int choice,i,position;
	bool firstclass[5] ={0};
	bool secondclass[10] ={0};
	char ch;
	int seats[10]={0};
	while(true)
	{
		cout<<"\t\tChoose your class\n";
		cout<<"\t1.First Class\n";
		cout<<"\t2.Second Class\t";
		cin>>choice;
		switch(choice)
		{
		case 1:
			cout<<"Seats available \n";			
                        int count = 0 ; 
                        for(i=0;i<MAX;i++)
                       {
				if (firstclass [i] == 0)
			        {
				        cout <<i<<" ";
				        count = i;
			          	break;
			      }
                       }
                        cout<<"\nChoose your seats (6-10)\n";
                        cin>>position;

			break;
			
			
		case 2:
			cout<<"Seats available \n";
			for(i=count ;i<MAX;i++)
			{
				cout<<i<<" ";
			}
			cout<<"\nChoose your seats "<<count << "and "<<MAX ;
                        cin>>position; 
                        firstclass[postion] = true ;
			break;
		}
		cout<<"Wish to continue(Y/N)\n";
		cin>>ch;
		if(ch=='y' || ch=='Y') continue;
		if(ch=='n' || ch=='N') exit(0);
	}

    return 0;

}
Last edited on
with the above code, im getting an error

(38) : error C2360: initialization of 'count' is skipped by 'case' label
what is this?
It means that sometimes count is initialized but other times it isn't, and because it is possible to access it in cases where it is not initialized, it would cause problems.

The solution is to put {} around the code after the case : statements.
Topic archived. No new replies allowed.