2d array help

I'm pretty confused on how to compare two "cells" in a 2 dimensional array. Im almost sure it's something with in my logic when checking the cells... any help on how i could check this would be great, thank you in advance for any help!


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
#include<iomanip>

#include<iostream>

using namespace std;


int main()
{	//variables
	int row_count(0);

	int col_count(0);

	int i, j;

	int count(0);
	
	char willdie('$');

	char dead('&');

	char alive('*');
	
	const int nrows(25);

	const int ncols(25);

	char global [25][25];

	char world[nrows][ncols];
	
	//generation one
	
	for (i=0;i<nrows; i++)
		{ for (j=0 ; j<ncols ; j++)
			{	
				world[i][j]=dead;
			}
		}

	for (i=0;i<nrows; i++)
		{ for (j=0 ; j<ncols ; j++)
			{	
				world[1][1]=world[1][2]=world[1][3]=alive;
			}
		}

	for (i=0;i<nrows; i++)
		{ for (j=0 ; j<ncols ; j++)
			{	
				cout << world[i][j];
			}
		cout << endl;
		}
	//end of generation one

	cout << "\n\n" << endl;
	//copying gen1 to global array

	for (i=0;i<nrows; i++)
		{ for (j=0 ; j<ncols ; j++)
			{	
				global[i][j]=world[i][j];
			}
		}
	
	for (i=0;i<nrows; i++)
		{ for (j=0 ; j<ncols ; j++)
			{	
				cout << global[i][j];
			}
		cout << endl;
		}
	//checking neighbors

	cout << "\n\n" << endl;

	for(i=0 ; i<nrows ; i++)
		{	
			for (j=0 ; j<ncols ; j++)
				{	count=0;
				//checking neighboring cells						

						if( global[i-1][j-1]=alive)
							{ 
								count++;
							}						
						if( global[i-1][j]=alive)
							{ 
								count++;
							}	

						if( global[i-1][j+1]=alive)
							{ 
								count++;
							}

						if( global[i][j-1]=alive)
							{ 
								count++;
							}

						if( global[i][j+1]=alive)
							{ 
								count++;
							}
						if( global[i+1][j-1]=alive)
							{
								count++;
							}
			
						if( global[i+1][j]=alive)
							{
								count++;
							}
		
						if( global[i+1][j+1]=alive)
							{ 
								count++;
							}
					
						//making note in global array if an alive cell dies
						if( count>2||count<2)
							{ 
								global[i][j]=willdie;
							}
						if(count=2)
							{
								global[i][j]=alive;
							}
					count=0;	
					//reset count for each cell
					}//end of j loop
				}//end of for loop to check alive cells
			
	for (i=0;i<nrows; i++)
		{ for (j=0 ; j<ncols ; j++)
			{	
				cout << global[i][j];
			}
		cout << endl;
		}
to be more clear what i mean by a cell would be like comparing..

[1][1] to [0][0],[0][1],[0][2],[1][0],[1][2],[2][0],[2][1],[2][2]
I changed one mistake with assigning in the if statement and changed it to a condition operator

...i.e
 
if (  global[i+1][j+1]==alive)
Topic archived. No new replies allowed.