Airplane Reservation issue

I am writing a program for school. The program is an airplane reservation program. I am trying to get the reservation saved to a file. It is giving me an debug error of Run-Time Check Failure #2 - Stack around the variable 'reservation' was corrupted. Any suggestions on fixing this issue?

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
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>

const int ROWS = 15; // number of rows for each section
const int COLS = 7; // number of columns for first class

void adminMenu();
void seatChartFC(int reservation[ROWS][COLS]);
void seatChartCoach(int reservation[ROWS][COLS]);
void seatChoice(int reservation[ROWS][COLS]);

using namespace std;

int main()
{
	int choice;
	int reservation[ROWS][COLS];

	cout << "1. Make a reservation\n" << "2. Admin Menu" << endl;
	cin >> choice;
	while (choice <= 0 || choice >= 3)
	{
		cout << "You entered an invalid choice please choose 1 or 2." << endl;
		cin >> choice;
	}
	if (choice == 1)
	{
		seatChartFC(reservation);
	}
	if (choice == 2)
	{
		adminMenu();
	}
	seatChoice(reservation);
	return 0;
}
void adminMenu()
{
	cout << "1. View total number of seats sold" << endl;
	cout << "2. View total number of seats empty" << endl;
	cout << "3. View total amount of sales" << endl;
}
void seatChartFC(int reservation[ROWS][COLS])
{
	string firstClass[ROWS];
	string column[COLS];

	cout << "\tFirst Class" << endl;

	firstClass[0] = "\t  1 2   3 4";
	cout << firstClass[0];



	for (int x = 0; x < 5; x++)
	{
		cout << "\n";
		cout << "Row " << (x + 1) << "\t  ";
		for (int y = 0; y < COLS - 2; y++)
		{
			column[2] = " ";
			if (column[y] == "" && column[y] != column[2])
				cout << "# ";
			else if (column[y] == column[2])
				cout << " ";
			else
				cout << "* ";
			cout << column[y];
		}
	}
	seatChartCoach(reservation);
}

void seatChartCoach(int reservation[ROWS][COLS])
{
	string firstClass[ROWS];
	string column[COLS];

	cout << "\n\n\tCoach" << endl;
	firstClass[6] = "\t1 2 3   4 5 6";
	cout << firstClass[6];

	for (int x = 5; x < ROWS; x++)
	{
		cout << "\n";
		cout << "Row " << (x + 1) << "\t";
		for (int y = 0; y < COLS; y++)
		{
			column[3] = " ";

			if (column[y] == "" && column[y] != column[3])
				cout << "# ";
			else if (column[y] == column[3])
				cout << " ";
			else
				cout << "* ";
			cout << column[y];
		}
	}
	cout << endl;
}
void seatChoice(int reservation[ROWS][COLS])
{	
	int x = 0;
	int y = 0;
	

	ofstream outputFile;
	outputFile.open("Users\chris_000\Documents\Visual Studio 2013\Projects\course project\course project\reservation.txt");

	cout << "Anavailable seat is indicated by a #. A seat with a * is reserved" << endl;
	cout << "Please choose an available Row number." << endl;
	cin >> reservation[x][COLS];
	cout << "Please choose an available Seat number" << endl;
	cin >> reservation[ROWS][y];
	outputFile << reservation[x][y];
	outputFile.close();
}
Last edited on
reservation[ROWS][COLS]
That means that reservation valid rows are [0; ROWS-1] and valid columns are [0; COLS-1]

reservation[x][COLS]; — invalid column number
reservation[ROWS][y]; — invalid row number
Topic archived. No new replies allowed.