I need help with array two dimensions

Hello everybody
I am doing the project about Game Of Life. Professor require that there shuold be a function create a menu, a function display the array, a function for testing. So far I'm done the menu and display. I can display the initial array now. But when I cout the initial array again in the main function, there are weird symbols pop up on screen and that may be the reason I cannot count the neighbors. When I cout the neighbors, there are only zero numbers.

These are the codes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void Display(char world[][NCOLS])
{
	int i,j;

	for(i=0;i<NROWS;i++)
	{
		for(j=0;j<NCOLS;j++)
		{
			if ( world[i][j] == 1)
			{
				cout<<"*"<<" ";
			}
			else
			{
				cout<<" "<<" ";
			}
		}
		cout<<endl;
	}
}

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
void Menu(char gen[][NCOLS], int ini)
{
	
	if(ini == 1)
	{
		gen[5][5] = 1;
		gen[5][6] = 1;
		gen[5][7] = 1;
		Display(gen);
	}

	if(ini == 2)
	{
		gen[5][5] = 1;
		gen[5][6] = 1;
		gen[6][5] = 1;
		gen[6][6] = 1;
		Display(gen);
	}

	if(ini == 3)
	{
		gen[5][5] = 1;
		gen[5][6] = 1;
		gen[5][7] = 1;
		gen[6][7] = 1;
		gen[7][6] = 1;
		Display(gen);
	}
	system("pause");
	return ;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main()
{
	char gen[NROWS][NCOLS];
	int ini,i,j;

	cout<<"Plese enter the ini: "<<endl;
	cin>>ini;

	Menu(gen, ini); //I can get the array right here
	for(i=0;i<NROWS;i++)
	{
		for(j=0;j<NCOLS;j++)
		{
			cout<<gen[i][j]<<" ";//But when I cout again, the weird symbols appear           
		}cout<<endl;
	}

	//Neighbor_Count(gen);//I can't count the neighbor.
	system("pause");
	return 0;
}


This is the Neighbor_Count
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
void Neighbor_Count(char world[][NCOLS])
{
	int i,j;
	
	for(i=0;i<NROWS;i++)
	{
		for(j=0;j<NCOLS;j++)
		{
			int neighbors(0);
	        if(world[i-1][j] == LIVE)
				neighbors ++;
			if(world[i+1][j] == LIVE)
				neighbors ++;
			if(world[i-1][j-1] == LIVE)
				neighbors ++;
			if(world[i+1][j+1] == LIVE)
				neighbors ++;
			if(world[i-1][j+1] == LIVE)
				neighbors ++;
			if(world[i+1][j-1] == LIVE)
				neighbors ++;
			if(world[i][j-1] == LIVE)
				neighbors ++;
			if(world[i][j+1] == LIVE)
				neighbors ++;
			cout<<neighbors<<" ";
		}
	}
	return;
}


Can you guy give me some opinion. I'm very appreciate that.
Last edited on
This is the output when I run the program
Plese enter the ini:
2





          * *
          * *


















Press any key to continue . . .
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ☺ ☺ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ☺ ☺ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠ ╠
Press any key to continue . . .
Hello!!!!!Anybody here ??? Please help me !!!!!
@binbk

One problem I see is, you've declared gen[][] to be char, but you're filling it with int's.
char gen[NROWS][NCOLS]; // Don't see where NROWS or NCOLS, is initiated

1
2
3
4
5
6
7
if(ini == 1)
	{
		gen[5][5] = 1; // Try using '1' on these
		gen[5][6] = 1;
		gen[5][7] = 1;
		Display(gen);
	}


For better help, maybe show the code for the whole program. Easier to see where errors may be lurking.

Hope this helped
@whitenite

Thank you very much. It's very helpful.
Topic archived. No new replies allowed.