I have an assignment for school to make a program called the game of life. This program takes values from a data file and places them in a 2d array. All the values taked are set to true in the array and any empty places default to false. Then it displays it on a grid of *'s for true and blank spaces for false. There are 20 rows and 20 colums in the grid. Then the program follows these rules to find the next generation of values from the grid:

If the cell is currently empty:
If the cell has exactly three living neighbors, it will come to life in the next generation.
If the cell has any other number of living neighbors, it will remain empty.
If the cell is currently living:
If the cell has one or zero living neighbors, it will die of loneliness in the next generation.
If the cell has four or more living neighbors, it will die of overcrowding in the next generation.
If the cell has two or three neighbors, it will remain living.
All births and deaths occur simultaneously. This point is critical to the correct result

I have written the code and from everything I see it should be working and compiles fine but for some reason I keep getting the wrong answer, can somone please let me know what I am doing wrong. For now all I want it to do is print the 2nd generation to the screen with the correct results.
The correct output for each grid can be found here: http://www.santarosa.edu/~dharden/10s08/proj5fullout.html

The data values that are read from the data file can be found at: http://www.santarosa.edu/~dharden/10s08/proj5data.html

I have included my main .cpp file for the code as an attachment. I was going to include the header file and the class member functions file as attachments but it wouldn't allow me to so I am posting them right here

Class code(i'm sorry for the length of this code):

//////////////////////Header//////////////////////
#include <iostream>
#ifndef BOOLMATRIX_H
#define BOOLMATRIX_H


const int rows = 20;
const int cols = 20;

 
class boolMatrix
{
	public: // Available for clients use.

	        boolMatrix();
            bool get(int row, int col);
            void set(int row, int col, bool answer);
            int rowcount(int row);
            int colcount(int col);
            int totalcount();
            void print();
		

	private: // Can only be used within the class, Client cannot call it.
            bool container[rows][cols];
};


#endif // BOOLMATRIX_H

/////////Class Member Functions////////////
#include <iostream>
#include "boolmatrix.h" // class's header file
#include <iomanip>


using namespace std;


// class constructor
boolMatrix::boolMatrix()
{
    for (int row = 0; row < rows; row++){
        for (int col = 0; col < cols; col++){    
             container[row][col] = false;
         }
    }
            
}


bool boolMatrix::get(int row, int col)
{
    return container[row][col];
}


void boolMatrix::set(int row, int col, bool answer)
{
     container[row][col] = answer;
}


int boolMatrix::rowcount(int row)
{
    int rowtotal = 0;
    
    for (int count = 0; count < rows; count++){
        if ( container[row][count] == true ){
           rowtotal++;
        }
    }
    return rowtotal;           
}


int boolMatrix::colcount(int col)
{
    int coltotal = 0;
    
    for (int count = 0; count < cols; count++){
        if ( container[count][col] == true ){
           coltotal++;
        }
    }
    return coltotal;                    
}


int boolMatrix::totalcount()
{
     int total = 0;
     for (int row = 0; row < rows; row++){
         for (int col = 0; col < cols; col++){ 
             if ( container[row][col] == true ){
                total++;
             }
         }     
     }
     return total;
     
}


void boolMatrix::print()
{
    int toptable[9];
    int sidetable[rows];
    int test = 0;
    
    cout << "  ";
    for ( int count = 0; count < 10; count++){
        toptable[count] = count;
    }
    
    for ( int row = 0; row < rows; row++){
        sidetable[row] = row;
    }

    for (int col = 0; col < cols; col++){    
        cout << toptable[test];
        test++;
        if ( test == 10 )
           test = 0;
    }
    cout << endl;

    for (int row = 0; row < rows; row++){
        cout << setw(2) << sidetable[row];
        for (int col = 0; col < cols; col++){    
            if ( container[row][col] == true ){
               cout << "*";
            } else if ( container[row][col] == false ){
              cout << " ";
            }
        }
        cout << endl;
    }      
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.