Writing a program to handle ticket sales...How do I initialize this multidimensional array of structs?

Hi, total fresh n00b to c++ here. I'm trying to solve a problem to handle ticket sales for a show. To represent the seats at the show, I made a 2D array, named chart, of structures, named "seat", which contain a string of characters for the customer name, a string of characters for the type of seat, and a boolean for whether or not the seat is available. Right now I'm trying to initialize this array. But I'm coming across a couple of difficulties.

I did the following:

int row;
int col;

for (row=0; row<15; row++){
for (col=0; col<25; col++){
strcpy(chart[row][col].customer,"blank");
strcpy(chart[row][col].type,"nul");
}
}


However, when I ask for the program to print the names of each seat in the theatre (chart[][].customer), I get a bunch of nul's instead. So I'm assuming what I did in the second line within the nested for loop overwrites what I did in the first line. Where am I messing up here and how can I fix it?

Much thanks in advance!
Somthing like this ???
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
#include <iostream>
#include <string>
#include <limits>
using namespace std;
struct chart
{
string customer[15][25];
string type[15][25];


};
int main()
{

struct chart list;
int row;
int col;

for (row=0; row<15; row++){
for (col=0; col<25; col++){
	list.customer[row][col]="blank";
	list.type[row][col]="null";
	cout<<"row: "<<row <<"col: "<<col<<" Inside customer:" <<list.customer[row][col]<<endl;
	cout<<"row: "<<row <<"col: "<<col<<" Inside type:" <<list.type[row][col]<<endl;
}
}
cin.clear();
cin.sync();
cout<<"Press Enter Key To Exit"<<endl;
cin.ignore( numeric_limits<streamsize>::max(),'\n' );
return 0;
}





or this ???
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
#include <iostream>
#include <string>
#include <limits>
using namespace std;
struct chart
{
string customer[15][25];
string type[15][25];


};
int main()
{


struct chart *lists = new struct chart;

int row;
int col;

for (row=0; row<15; row++){
for (col=0; col<25; col++){
	lists->customer[row][col]="blank";
	lists->type[row][col]="null";
	cout<<"row: "<<row <<"col: "<<col<<" Inside  customer:" <<lists->customer[row][col]<<endl;
	cout<<"row: "<<row <<"col: "<<col<<" Inside  type:" <<lists->type[row][col]<<endl;
}
}
delete lists;
cin.clear();
cin.sync();
cout<<"Press Enter Key To Exit"<<endl;
cin.ignore( numeric_limits<streamsize>::max(),'\n' );
return 0;
}
Last edited on
Topic archived. No new replies allowed.