Okay this is what I have so-far:
Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
//Global Variables
const int ROWS = 12;
const int COLS = 30;
const int BOARD_ROWS(10);
const int BOARD_COLS(28);
const char LIVE = 'X'; //life cells
const char DEAD = '.'; //dead cells
//functions
void MakeArray(string filename, char board[][COLS]);
void GameBoard(char board[][COLS]);
void NextState(char board[][COLS]);
int main()
{
char board [ROWS][COLS];
string filename; //Name of the file
cout<<"Enter the filename: \n";
cin>>filename;
//call functions
MakeArray(filename, board);
NextState(board);
GameBoard(board);
//stop terminal window from quitting after programs ends
char q;
cin >> q;
return 0;
}
void MakeArray(string filename, char board[][COLS])
{
ifstream myfile;
myfile.open (filename.c_str());
for (int r=0; r<ROWS; r++)
{
for (int c=0; c<COLS; c++)
{
myfile>>board[r][c];
}
}
myfile.close();
}
void GameBoard (char board[][COLS])
{
for (int r=0; r<ROWS; r++)
{
for (int c=0; c<COLS; c++)
{
cout<<board[r][c];
}
cout<<endl;
}
}
void NextState (char board[][COLS])
{
int LiveCnt=0;
for (int r=0; r<ROWS; r++)
{
for (int c=0; c<COLS; c++)
{
if (board[r-1][c-1]=='X')
{
LiveCnt++;
}
if (board[r-1][c]=='X')
{
LiveCnt++;
}
if (board[r-1][c+1]=='X')
{
LiveCnt++;
}
if (board[r][c-1]=='X')
{
LiveCnt++;
}
if (board[r][c]=='X')
{
LiveCnt++;
}
if (board[r][c+1]=='X')
{
LiveCnt++;
}
if (board[r+1][c-1]=='X')
{
LiveCnt++;
}
if (board[r+1][c+1]=='X')
{
LiveCnt++;
}
}
cout<<endl;
}
}
Now I need to have another if statement for the rules? How do I do that?