pa5.cpp:77: error: incompatible types in assignment of `int' to `int[80]'
anyway i was wondering if anyone could give me some hints about what i am doing wrong.
here is the code
#include <iostream>
#include <cstdlib>
using namespace std;
void setupRow();
void printRow();
void updateRow();
int findNextCellState(int left_neighbor, int cell, int right_neighbor);
const int WIDTH=80;
int row[WIDTH];
int i;
int main()
{
setupRow();
printRow();
for (int i = 0; i < 40; i++)
{
updateRow();
printRow();
}
}
// The setupRow function creates an initial state for the cellular
// autonoma
void setupRow()
{
for (int i = 0; i < WIDTH; i++)
{
if( i == WIDTH)
{
row[i] = 1;
}
else
{
row[i] = 0;
}
}
}
// The printRow 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 printRow()
{
for (int i = 0; i < WIDTH; i++)
{
if( row[i] == 0)
{
cout << " ";
}
}
cout << endl;
}
// The updateRow function updates the contents of the row after
// calculating
// the next states using the findNextCellState function
void updateRow()
{
int temp_row[WIDTH];
for( i = 0; i < WIDTH; i++)
{
temp_row = row[i];
}
for ( int i = 0; i < WIDTH; i++)
{
int left_neighbor = i-1;
int cell = i;
int right_neighbor = i+1;
if ( left_neighbor > WIDTH)
{
left_neighbor = 0;
}
if ( right_neighbor > WIDTH)
{
right_neighbor = 0;
}
row[i] = findNextCellState( temp_row[left_neighbor],
temp_row[right_neighbor], temp_row[cell]);
}
}
// The findNextCellState 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 findNextCellState(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;
}
}
}
Thanks!

New Topic/Question
Reply



MultiQuote



|