That looks right (I assume it works).
Now you need to write the function that actually calculates the next state of the board. Let's call it NextState and give it the prototype:
Code:
void NextState(board[][COLS]);
Try writing it. It will need another board, say board2, locally defined in NextState to be the same type as board in main.You'll need to write a double loop to go through board and count how many LIVE neighbors each cell has. If the cell itself is LIVE, then it will only remain LIVE if it has 2 or 3 neighbors, otherwise it will be DEAD. If the cell is DEAD then it will remain DEAD if it has
anything but 3 neighbors; if it has exactly 3 neighbors it will become LIVE.
You'll set board2 to these new values. After the end of the double loop going through board, you'll have another double loop to simply copy board2 back into board to give it its new state.
Give that a try. Your main for now should be something like:
Code:
int main()
{
char board [ROWS][COLS];
string filename; //Name of the file
cout<<"Enter the filename: \n";
cin>>filename;
MakeArray(filename, board);
GameBoard(board);
NextState(board);
GameBoard(board);
//stop terminal window from quitting after programs ends
char q;
cin >> q;
return 0;
}