Code:#include <iostream.h> const int ROW = 7; const int COL = 7; void main() { char M[ROW][COL]={ {' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ','*','*',' ',' '}, {' ',' ','*',' ','*',' ',' '}, {' ',' ',' ',' ','*',' ',' '}, {' ',' ','*',' ',' ',' ',' '}, {' ',' ','*',' ','*',' ',' '}, {' ',' ',' ',' ',' ',' ',' '} }; int num = 0; cout << "\nPlease enter the number of generations to print: "; cin >> num; cout << "\n\n\tGeneration: " << 0 << endl; for (int i=1; i<ROW-1; i++){ cout << endl << "\t" << '|'; for (int j=1; j<COL-1; j++){ cout << M[i][j] << '|'; }//for }//for cout << endl <<endl; for (int k=0; k<num; k++){ for (int i=1; i<ROW-1; i++){ for (int j=1; j<COL-1; j++){ if (M[i-1][j] == '*') num++; if (M[i-1][j-1] == '*') num++; if (M[i-1][j=1] == '*') num++; if (M[i][j-1] == '*') num++; if (M[i][j+1] == '*') num++; if (M[i+1][j] == '*') num++; if (M[i+1][j-1] == '*') num++; if (M[i+1][j+1] == '*') num++; }//for }//for cout << "\tGeneration: " << k+1 << endl; for (int i=1; i<ROW-1; i++){ cout << endl << "\t" << '|'; for (int j=1; j<COL-1; j++){ cout << M[i][j] << '|'; }//for }//for cout << endl <<endl; }//for }//main
Here is my code. When I try to execute this, it will only print the first generation no matter how many generation I enter. What am I doing wrong?



LinkBack URL
About LinkBacks


