I have been given a skeleton code, and it has been verified as accurate, i just need help with the finer details. I cant figure out how to write the update_row function into another array, and they save that array into the global array, and start the process over again. Any insight would be appreciated.
#include <iostream>
#include <cstdlib>
using namespace std;
void setup_row();
void print_row();
void update_row();
int find_next_cell_state(int left_neighbor, int cell, int right_neighbor);
const int WIDTH=80;
int row[WIDTH];
int array[WIDTH];
int main()
{
setup_row();
print_row();
for (int i = 0; 42 > i ; i++)
{
update_row();
print_row();
}
}
// The setup_row function creates an initial state for the cellular autonoma
void setup_row()
{
for(int i=0; 38 > i; i++)
{
row[i] = 0;
}
row[39] = 1;
for(int i = 40; 79 > i; i++)
{
row[i] = 0;
}
}
// The print_row function outputs the state of the row to the user. For all
// cells that are 0, it outputs a space (" "), for all cells that are 1, it
// outputs a star ("*")
void print_row()
{
for(int i =0; i < 80; i++)
// The update_row function updates the contents of the row after calculating
// the next states using the find_next_cell_state function
void update_row()
{
for (int i =80; i < 80; i++)
{
int left_neighbor, cell, right_neighbor, a;
left_neighbor = row[0] +=3;
cell = row[1] +=3;
right_neighbor = row[2] +=3;
int array[a] = find_next_cell_state( left_neighbor, cell, right_neighbor);
}
}
// The find_next_cell_state function implements the Rule 30 celular autonoma rules.
// The states for this are:
//
// 111 110 101 100 011 010 001 000
// 0 0 0 1 1 1 1 0
int find_next_cell_state(int left_neighbor, int cell, int right_neighbor)
{
if (0 == cell)
{
if (1 == (left_neighbor + right_neighbor))
{
return 1;
}
else
{
return 0;
}
}
else
{
if (1 == left_neighbor)
{
return 0;
}
else
{
return 1;
}
}
}