All I'm getting is a blank array, when I go from the 0 generation to the next one.
There's probably some simple steps I'm missing, but for the life of me, I can not figure them out. (I'm very much a beginning programmer, only in my first programming class)
this is the function I'm working on that's giving me trouble:
Expand|Select|Wrap|Line Numbers
- void CalculateNextGeneration (char Board [NumRows] [NumCols])
- {
- int Count; //count how many '*' are present
- char Board2 [NumRows] [NumCols];
- for (int i =0; i <= NumRows; i++) //initialize 2nd array
- {
- for (int j = 0; j < NumCols; j++)
- {
- Board2 [i] [j] = Board [i] [j];
- }
- }
- for (int i = 0; i < NumRows; i++)
- {
- for (int j = 0; j < NumCols; j++)
- {
- Count = 0; //resets for each loop
- if (Board [i - 1] [j - 1] == '*' ) // check upper left for neighbors
- {
- Count++;
- }
- else if (Board [i] [j - 1] == '*' ) //check above
- {
- Count++;
- }
- else if (Board [i + 1] [j - 1] == '*' ) //upper right
- {
- Count++;
- }
- else if (Board [i - 1] [j] == '*' ) //in front
- {
- Count++;
- }
- else if (Board [i + 1] [j] == '*' ) //after
- {
- Count++;
- }
- else if (Board [i - 1] [j + 1] == '*' ) //bottom left
- {
- Count++;
- }
- else if (Board [i] [j + 1] == '*' ) //below
- {
- Count++;
- }
- else if (Board [i + 1] [j + 1] == '*' ) //bottom right
- {
- Count++;
- }
- if (Count == 3) // born if 3 neighbors
- {
- Board2 [i] [j] = '*';
- }
- else if ((Count <= 1) || (Count >= 4)) // dies if more then 3 (so 4 or more) neightbors, or less then 2 (1 or 0)
- {
- Board2 [i] [j] = ' ';
- }
- }
- }
- Generation++;
- Display (Board2);
- }
Any help or advice/tips I could get?