I'm trying to create this pattern: http://mathworld.wolfram.com/Rule60.html
I cannot get my code to print this. It runs, it just does not print the right pattern. I know I am doing something wrong, I'm just not sure what.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
//Declare variables
bool line[78];
bool nextLine[78];
void firstline();
void coutline();
void rules();
void coutnextline();
int r;
//Create first line
firstline();
//Cout Line
coutline();
//Next Lines
for (r = 0; r < 15; r++)
{
rules();
coutnextline();
}
cin.get();
return 0;
}
//Create first line
void firstline ()
{
//declare variables
bool line [78];
int y;
for(y = 1; y < 78; y++)
{
if(y != 39)
line[y] = 0;
else if(y == 39)
line[y] = 1;
}
}
//Cout line
void coutline()
{
//declare variables
bool line [78];
int z;
for(z = 0; z <= 78; z++)
{
if(line[z] == 0)
cout << " ";
else if(line[z] == 1)
cout << "#";
}
}
void rules ()
//Put line in and follow 8 rules
// Rule: 1 2 3 4 5 6 7 8
// 111 110 101 100 011 010 001 000
// 0 0 0 1 1 1 1 0
{
//Declare variables
bool line[78];
int x;
bool nextLine[78];
for (x=1; x < 78; x++)
{
//rule 1
if (line[x-1] == 1 && line[x] == 1 && line [x+1] == 1)
nextLine[x] = 0;
//rule 2
else if (line[x-1] == 1 && line[x] == 1 && line [x+1] == 0)
nextLine[x] = 0;
//rule 3
else if (line[x-1] == 1 && line[x] == 0 && line [x+1] == 1)
nextLine[x] = 0;
//rule 4
else if (line[x-1] == 1 && line[x] == 0 && line [x+1] == 0)
nextLine[x] = 1;
//rule 5
else if (line[x-1] == 0 && line[x] == 1 && line [x+1] == 1)
nextLine[x] = 1;
//rule 6
else if (line[x-1] == 0 && line[x] == 1 && line [x+1] == 0)
nextLine[x] = 1;
//rule 7
else if (line[x-1] == 0 && line[x] == 0 && line [x+1] == 1)
nextLine[x] = 1;
//rule 8
else if (line[x-1] == 0 && line[x] == 0 && line [x+1] == 0)
nextLine[x] = 0;
}
}
void coutnextline()
{
//declare variables
bool nextLine [78];
int a;
for(a = 0; a <= 78; a++)
{
if(nextLine[a] == 0)
cout << " ";
else if(nextLine[a] == 1)
cout << "#";
}
}