writing a cellular "game of life" program having a little trouble

Thanks for the help
Last edited on
What exactly is it supposed to be doing? I don't really understand what you are trying to get it to do.
ok, it looks at the current generation, if the relative cells to it (that cell, one up, one down, one left, one right) if 3 or 4 of them are a 1 it stays or is made a 1 if <3 or >5 are a 1 it becomes a 0, it does this for 5 generations
Line 41/43 don't seem to make sense together...I think you meant to reverse the < > on line 41...and you might as well just make line 43 an else statement.

Other then that...your display code is outside of the 5 loops, so you will never see the results of those, you need to move it inside of it.
your right about line 41/43, but I dont understand what you mean about the display code, it seems to be in the loop to me, can you show me what you mean
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
int main ()
{
const int numrows = 10;
const int numcols = 10;
ifstream input;
ofstream results;
input.open("/Users/putyoursoxon/Documents/input.txt");//input file
results.open("/Users/putyoursoxon/Documents/results.txt");//application results go here
int i, j, g, h, count, loopa;
int arraypast[numrows][numcols];
int arrayfuture[numrows][numcols];

//BEGIN DISPLAY CODE
for (i=0; i < numrows; i ++)
{
for (j=0; j < numcols; j ++)
	input >> arraypast[i][j];
}

	for (i=0; i < numrows; i ++)
	{
		results << endl;
		for (j=0; j < numcols; j ++)
			results << arraypast[i][j];
	}
	results << endl;

//END DISPLAY CODE
	

//BEGIN LOOP CODE
for(loopa =1; loopa <= 5; loopa ++)
	{
	for (i=0; i < numrows; i++)
	 {
		 for (j=0; j < numcols; j++)
		 {
		 count = 0;
		 compare (arraypast, count, i, j);
		 if (count <=3 && count >=4)
			 arrayfuture[i][j] =1;
		 if (count > 3 || count == 5)
			 arrayfuture[i][j] =0;
		 }
	 }
		results << "Offspring #" << loopa << endl;
		for (g=0; i < numrows; i ++)
		{
			results << endl;
			for (h=0; j < numcols; j ++)
				results << arrayfuture[g][h];
		}
		results << endl;
		arraypast == arrayfuture;
		
	}
//END LOOP CODE
	return 0;
}
i cant see how that would work, the display code for the origin is outside the loop yes, but then the display code for the future array is inside, it is printed (not working) then arrayfuture is == arraypast and the loop is started again, so
I guess what I am trying to say is that the arrayfuture has to be inside the for loop since it changes every pass, it's printing offspring #1 etc. So the loop is working, but why am I getting no output at all for the array
Ah...Yeah I just noticed that ^^; the problem is:

1
2
3
4
5
6
for (g=0; i < numrows; i ++)
		{
			results << endl;
			for (h=0; j < numcols; j ++)
				results << arrayfuture[g][h];
		}


You forgot to change i/j to g/h.
Topic archived. No new replies allowed.