Error changing character in a multi-dimensional array

Hey there all. I know you must get this a lot but I'm tearing my hair out trying to get this program to work. For it, I need to display a grid (6*10) and change the values inside to indicate a seat has been taken. For this I am using the characters 'o' and 'X'. The grid itself displays fine but once I try and change the value from an o to an X command prompt crashes with a generic "project.exe has stopped working" error. I would appreciate any insight and will gladly provide any helpful information to help solve this most likely simple mystery.

Here is all my coding thus far from the project:

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

using namespace std;

int main(){

char grid[10][6];
char empty = 'o';
char taken = 'X';
char ans = 'y';
	
cout << "===========================================================\n===Welcome to the Terrific Software Seat Booking Program===\n===========================================================\n\n";

do{
	int answer = 0;

	cout << "Please select what you want to do from the menu below\n\n";
	cout << "[1] Check current avialible seats\n[2] Book a seat\n[3] Check seating plan\n\n";

	cin >> answer;
	cout <<"\n";

	switch (answer)
	{
		case 1:
			{

				for (int i =0; i < 10; i ++){
					cout << "\n" << i+1;
					for (int j =0; j < 6; j++){
						cout << "\t"; 
						grid[i][j] = empty;
						cout << grid[i][j];
					}
					cout << "\n\n";
				}
				break;
			}
	

		case 2:
			{
				char ans;
				int ans2;
				string name[10][6];
				
					cout << "What row do you wish to be seated on? (1-10)\n";
					cin >> ans;
					cout << "And what column? (A-F)\n";
					cin >> ans2;

				int row;
				row = ans;

				int column; 
				column = ans2-65;
				
					
		 	for (int i =0; i < 10; i ++){
					cout << "\n" << i+1;
					for (int j =0; j < 6; j++){
						cout << "\t"; 
						grid[i][j] = empty;
						cout << grid[i][j];
					}
					cout << "\n\n";
					}
				
				char empty = 'o';
				char full = 'X';
				
					if (grid[row][column-1] = empty)
					{
						grid[row][column-1] = full;
						cout << "What name do you wish to book this seat under?\n";
						cin >>  name[row][column-1];

						for (int i =0; i < 10; i ++){
						cout << "\n" << i+1;
							for (int j =0; j < 6; j++){
							cout << "\t"; 
							cout << grid[i][j];
					}
					cout << "\n\n";
					}
				}
					else
					{
						cout << "The seat is currently taken, please try another seat\n";
				}
					
				}
				break;	
				
			}

		
	cout << "\nDo you wish to select another option from the menu? [Y]es/[N]o\n";
	cin >> ans;
	cout << "\n";

}while(ans=='y'|| ans=='Y');

	cout << "Thank you for using the seat booking program\n";
	return 0;
} 


Thank you in advance for any assistance you can offer me.
Last edited on
if (grid[row][column-1] = empty) should be if (grid[row][column-1] == empty)

You ask people what row they want, and you store their input in a single char. So what happens if they enter 10? That's two chars. You then store that char value in an int, which is insane. The int value of the char '3', for example, is 51 ( www.asciitable.com ), so now you're working with the row value 51. Which does not exist.

You need to go back over the basics of what kind of data you're trying to get from the user, and store them in suitable types.

Also, learn to debug. Here's the first step: cout << "value currently stored in row is " << row << endl;
Last edited on
if (grid[row][column-1] = empty) should be if (grid[row][column-1] == empty)


Thank you for your help. Unfortunately, I implemented it into my code and still receive the same error. Also worth noting when I select 10 as the row number the code skips to asking what the delegate's name is seated there so the constraints of my arrays may have a part to play.

Just seen the edit. I think the char to int conversion is a remnant of something I was trying earlier to do with ASCII values. Would you suggest making both arrays int-based instead?
Last edited on
I'd probably use a single array of ten string objects.
Topic archived. No new replies allowed.