Unhandled Exception: Access Violation

Hello, and thank you to anyone willing to help.

I am a bit frustrated since I am trying to get my error handling working and I keep running into this unhandled exception error.

I am simply writing a function to check the input to make sure it is not out of the range of the the seating arrangement ie. if the user wants 3 rows (0 to 2) and 4 seats (a, b, c, d), then I want to make sure when they reserve a flight that the rows are not less than 0 or greater than 2 (or 1 less than input_row). Also, I will make sure that the user enters a letter for the seat assignment, and that the seat letter they choose is not less than a, or greater than input_seat.

I keep getting this unhandled exception error when I select a row that is greater than what is mapped, or less than 0...ie. if I select 2 rows for input row, then try to assign myself row 5 for a reservation, I end up with this error. What am I doing wrong?

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
//Airplane seat assignment

#include <iostream>
#include <cmath>
#include <string>

using namespace std;

typedef char* charArray;
typedef charArray* char2Array;

char again;

void check_row(int& input_row);
void check_seat(char& input_seat, int& col);
void display_seating(char2Array a, int rows, int seats);

//void assign_seat(char2Array a, int rows, int row, int col, char& valid);

int main()

{
using namespace std;

int row, col;
int input_row;
char valid = 'T';

char input_seat;
int rows, seats;

cout << "Please list the number of rows the plane has: ";
cin >> rows;

cout << "Seats in each row: ";
cin >> seats;

charArray *seat = new charArray[rows];
for(row = 0; row < rows; row++)
seat[row] = new char[seats];

for(row = 0; row < rows; row++)
for(col = 0; col < seats; col++)
seat[row][col] = static_cast<char>(toupper('A') + col);

do
{
cout << endl;
display_seating(seat,rows,seats);

cout << "\nPlease select a seating assignment from the seating arrangement displayed above."
	 << "Enter the numeric row number" 
	 << " followed by the letter of your seat choice: ";
cin >> input_row >> input_seat;
col = toupper(input_seat) - toupper('A'); 



	do
	{
		//check_row(input_row);
		if (seat[input_row][col] == 'X')
			{
				cout << "\nYou chose: "<< input_row << static_cast<char>(toupper('A') + col) << " which was reserved by another customer.";
				valid = 'F';
			}
		else
			{
				seat[input_row][col] = 'X';
				cout << "\nYou successfully reserved seat: " << input_row << static_cast<char>(toupper('A') + col) << " Thank you for flying with Argyle Express.";
				valid = 'T';
			}
	}while (valid = 0);

	


cout << "\nWould you like to make another reservation?";
cin >> again;

}while (again != 'N' || again != 'n');

return 0;
}

 
void display_seating(char2Array a, int rows, int seats)

{
using namespace std;
for(int row = 0; row < rows; row++)
{

cout << row;
for(int col = 0; col < seats; col++)

{

cout << a[row][col];

}

cout << endl;

}

}

void assign_seat(char2Array a, int rows, int row, int col, char& valid)
{
	using namespace std;

	// if the chosen seat has a x in it, then the seat is not valid
	if (a[row][col] == 'X')
		{
			valid = 'F';
		}
	else //The seat is valid and will become reserved by placing a x in it
		{
			a[row][col] = 'X';
			valid = 'T';
		}
}

void check_row(int& input_row)
{
	if (input_row < 0 || input_row > input_row -1 || input_row != isdigit(input_row))
		cout << "The row you selected is not available.";
	return;
}

void check_seat(char& input_seat, int& col)
{
	// This function checks to make sure the input is within the acceptable range for 'row' and 'col'
	using namespace std;

	if (!isalpha(input_seat))
		cout << "You must select a letter"; 
	if ((col < 'a' || col > input_seat) || (col < 'A' || col > input_seat ))
		cout << "You chose seat " << static_cast<char>(toupper('A') + col) << " but must choose a seat \n "
			 << "that is between A and " << static_cast<char>(toupper('A') + col);
}


Thank you,

Warmaster
if (input_row < 0 || input_row > input_row -1 || input_row != isdigit(input_row))

This is your check. So if there are 5 rows in the aircraft, which of these checks is checking that input_row is one of those 5? None of them.

input_row > input_row -1

When will this ever be false?
Last edited on
doh! I have been messing with this for 2 days now and I am apparently not seeing straight..thanks for pointing that out.
Topic archived. No new replies allowed.