123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
#include<iomanip> #include<iostream> using namespace std; int main() { //variables int row_count(0); int col_count(0); int i, j; int count(0); char willdie('$'); char dead('&'); char alive('*'); const int nrows(25); const int ncols(25); char global [25][25]; char world[nrows][ncols]; //generation one for (i=0;i<nrows; i++) { for (j=0 ; j<ncols ; j++) { world[i][j]=dead; } } for (i=0;i<nrows; i++) { for (j=0 ; j<ncols ; j++) { world[1][1]=world[1][2]=world[1][3]=alive; } } for (i=0;i<nrows; i++) { for (j=0 ; j<ncols ; j++) { cout << world[i][j]; } cout << endl; } //end of generation one cout << "\n\n" << endl; //copying gen1 to global array for (i=0;i<nrows; i++) { for (j=0 ; j<ncols ; j++) { global[i][j]=world[i][j]; } } for (i=0;i<nrows; i++) { for (j=0 ; j<ncols ; j++) { cout << global[i][j]; } cout << endl; } //checking neighbors cout << "\n\n" << endl; for(i=0 ; i<nrows ; i++) { for (j=0 ; j<ncols ; j++) { count=0; //checking neighboring cells if( global[i-1][j-1]=alive) { count++; } if( global[i-1][j]=alive) { count++; } if( global[i-1][j+1]=alive) { count++; } if( global[i][j-1]=alive) { count++; } if( global[i][j+1]=alive) { count++; } if( global[i+1][j-1]=alive) { count++; } if( global[i+1][j]=alive) { count++; } if( global[i+1][j+1]=alive) { count++; } //making note in global array if an alive cell dies if( count>2||count<2) { global[i][j]=willdie; } if(count=2) { global[i][j]=alive; } count=0; //reset count for each cell }//end of j loop }//end of for loop to check alive cells for (i=0;i<nrows; i++) { for (j=0 ; j<ncols ; j++) { cout << global[i][j]; } cout << endl; }
if ( global[i+1][j+1]==alive)