Airline Reservations help

Hello,
I am having all types of issues with writing this program. I don't really know where to go from here on fixing it and I just read over the requirements for the assignment again and I missed the first time that the prices for the seats need to be opened from a file and stored as an array of doubles. If you can help me please I would really appreciate it. Thank you!

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <iostream>
#include <string>
#include <fstream>
#include <ctime>
#include <cstdlib>
using namespace std;

void begin();
void menu();
void checkSeat();
void printTicket();
const int first = 1000;
const int economy = 500; 
const int rows = 9;
const int col = 5;
const int size = 50;
char seat[rows][col];
double price, discount;
string type, sname, name[rows][col];
bool answer;

void begin()
{
    char letters[11] = "ABCDEFGHIJ";
    char letter;
	for ( int row = 0; row < rows; row++ )
    {
        letter = letters[row];
        col < 5;
        col ++;
	}
}

void menu()
{
	cout << "Please choose one of the following:\n ";
    cout << "1. First Class seating\n";
    cout << "2. Economy seating\n";
    cout << "3. Seating allocation\n";
    cout << "4. Ticket holder\n";
}

void checkSeat()
{
	char reply;
	cout << "Enter name:";
    cin >> sname;
    cout << "Do you want a specific seat:(y/n) : ";
    cin >> reply;
    if( reply == 'y' )
	{
		begin();
        cout << "Enter seat: \n";
        cin >> seat[rows][col];
       
		if(seat[rows][col] == 'X')
		{
			seat[rows][col] = 'X';
            name[rows][col] = sname;
        }
        else
        {
			int x = rand()%rows;
            int y = rand()%col;
            while(seat[x][y] == 'X');
                {
					int x = rand()%rows;
                    int y = rand()%col;
                }
				seat[rows][col] = 'X';
                name[rows][col] = sname;
        }
      }
      else
      {
		  begin();
          int rows = rand()%rows;
          int columns = rand()%columns;
          while ( seat[rows][columns] = 'X')
          {
			  int rows = rand()%rows;
              int columns = rand()%columns;
          }
		  seat[rows][columns] = 'X';
          name[rows][columns] = sname;
      }
}

void printTicket()
{
	cout <<"Name: " << name << endl;
    cout << "Seat No: " << seat << endl;
    cout << "Ticket type: " << type << endl;
    cout << "price: " << price << endl;
}
       
int main()
{
	int choice;
    srand(time(NULL));
    count < 50;
    count ++;
	{
		menu();
        cin >> choice;
        switch (choice)
		{
			case 1:  type = "First class";
			begin();
			int rows = 9;
			{
				checkSeat();
                bool isleSeat1 = seat[rows][1];
                bool isleSeat2 = seat[rows][2];
                if ( isleSeat1 == true || isleSeat2 == true )
				{
					discount = 10 / 100 * first;
                    price = first - discount;
				}
				else
				{
					price = first;
                }
             }
				break;
                case 2:  type = "Economy";
                begin();
				while( rows > 2 )
				{
					checkSeat();
                    bool isleSeat1 = seat[rows][1];
                    bool isleSeat2 = seat[rows][2];
					if ( isleSeat1 == true || isleSeat2 == true )
					{
						discount = 10 / 100 * first;
                        price = first - discount;
					}
					else
					{
						price = first;
                    }
                 }
					break;
                    case 3:  
				    printTicket();
                    break;
                    case 4: default: cout << "Incorrect. Choose between 1-4 \n";
          }
       }
            return 0;
}
These are the compiler errors/warnings I'm getting on the code.

line 29 does nothing
line 30 - col is a const int variable - you can't change its value as you do here
lines 67-68 declare new variables that aren't used
line 79 - you probably want == here, not =
line 101-2 - the main function doesn't know what the count variable is
line 110 - you've already declared a global const variable called rows - the compiler does not like you declaring a new local variable with the same name here

Info on arrays
http://www.cplusplus.com/doc/tutorial/arrays/

Working with files
http://www.cplusplus.com/doc/tutorial/files/
Thank you. So I fixed those issues and I'm looking in to the info you provided. Now it says I don't have any errors but it does not exactly run properly and I'm still not sure why. Any advice?

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <iostream>
#include <string>
#include <fstream>
#include <ctime>
#include <cstdlib>
using namespace std;

void begin();
void menu();
void checkSeat();
void printTicket();
void displaySeating();
const int first = 1000;
const int economy = 500; 
const int rows = 9;
const int col = 5;
const int size = 50;
char seat[rows][col];
double price, discount;
string type, sname, name[rows][col];
bool answer;

void begin()
{
    char letters[11] = "ABCDEFGHIJ";
    char letter;
	for ( int row = 0; row < rows; row++ )
    {
        letter = letters[row];
        row < 5;
        row ++;
	}
}

void menu()
{
	cout << "Please choose one of the following:\n ";
    cout << "1. First Class seating\n";
    cout << "2. Economy seating\n";
    cout << "3. Seating allocation\n";
    cout << "4. Ticket holder\n";
}

void checkSeat()
{
	char reply;
	cout << "Enter name:";
    cin >> sname;
    cout << "Do you want a specific seat:(y/n) : ";
    cin >> reply;
    if( reply == 'y' )
	{
		begin();
        cout << "Enter seat: \n";
        cin >> seat[rows][col];
       
		if(seat[rows][col] == 'X')
		{
			seat[rows][col] = 'X';
            name[rows][col] = sname;
        }
        else
        {
			int x = rand()%rows;
            int y = rand()%col;
            while(seat[x][y] == 'X');
                {
					int x = rand()%rows;
                    int y = rand()%col;
                }
				seat[rows][col] = 'X';
                name[rows][col] = sname;
        }
      }
      else
      {
		  begin();
          int rows = rand()%rows;
          int columns = rand()%columns;
          while ( seat[rows][columns] == 'X')
          {
			  rows = rand()%rows;
              columns = rand()%columns;
          }
		  seat[rows][columns] = 'X';
          name[rows][columns] = sname;
      }
}

void printTicket()
{
	cout <<"Name: " << name << endl;
    cout << "Seat No: " << seat << endl;
    cout << "Ticket type: " << type << endl;
    cout << "price: " << price << endl;
}
       
void displaySeating()
        {
        }

int main()
{
	int choice, count;
    srand(time(NULL));
    count < 50;
    count ++;
	{
		menu();
        cin >> choice;
        switch (choice)
		{
			case 1:  type = "First class";
			begin();
			{
				checkSeat();
                bool isleSeat1 = seat[rows][1];
                bool isleSeat2 = seat[rows][2];
                if ( isleSeat1 == true || isleSeat2 == true )
				{
					discount = 10 / 100 * first;
                    price = first - discount;
				}
				else
				{
					price = first;
                }
             }
				break;
                case 2:  type = "Economy";
                begin();
				while( rows > 2 )
				{
					checkSeat();
                    bool isleSeat1 = seat[rows][1];
                    bool isleSeat2 = seat[rows][2];
					if ( isleSeat1 == true || isleSeat2 == true )
					{
						discount = 10 / 100 * first;
                        price = first - discount;
					}
					else
					{
						price = first;
                    }
                 }
					break;
                    case 3:  
				    printTicket();
                    break;
                    case 4: default: cout << "Incorrect. Choose between 1-4 \n";
          }
       }
            return 0;
}
line 30: As pointed out previously, this line doesn't do anything. What do you think this line does?

Line 106: ditto

Line 117-118: You're assigning a char to a bool. What are you trying to do here?

Line 135-136: Ditto.

Line 78-79: You're referencing the local uninitialized variable here, not the global const at line 15-16.

Line 107: You're incrementing an uninitialized variable.



I'd try walking through the code on paper or through a debugger and following how values of variables are getting assigned.

Entering the name - if you're expecting them to enter a first and last name, you'll want to look into using getline because the cin will stop at the blank space between first and last names.

Entering seat - it's not clear what is supposed to be entered there. Is a seat map supposed to be displaying so I know what seat I can choose?

It looks like the content of the seat array will have values like 'X', but then you try to assign that to a bool variable?
while(seat[x][y] == 'X');
bool isleSeat1 = seat[rows][1];

What is the begin function supposed to do? I threw in some cout statements to illustrate what's happening there. The letter variable doesn't get used anywhere else so I'm not sure what you mean to do here.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void begin()
{
    char letters[11] = "ABCDEFGHIJ";
    char letter;
	for ( int row = 0; row < rows; row++ )
    {
        cout << "row is now " << row << endl;
        letter = letters[row];
        cout << "letter is now " << letter << endl;
        row < 5;
        row ++;
        cout << "row is now " << row << endl;
	}
row is now 0
letter is now A
row is now 1
row is now 2
letter is now C
row is now 3
row is now 4
letter is now E
row is now 5
row is now 6
letter is now G
row is now 7
row is now 8
letter is now I
row is now 9


Topic archived. No new replies allowed.