I need a little help with this PRG. First time it ask for it to move on to the next Generation. But doesn't ask second time. I did wrote using all Functions. So it'll be really helpful if answered clearly. Also it doesn't seem to give the proper answer(such as '****' or ' '). This was part of the Assignment. and the question for it is:

Write a program to implement the simulation of life as described in Scientific American by Martin Gardner. The program will be implemented on a two dimensional surface of size 60 by 60 visible elements. The rules of the simulation are as follows:
1) An initial set of cells are marked as “alive” by the user. This is generation 0. Your program will ask the user to input a set of row and column values to let the user determine which cells are “alive”. Display this generation.
2) Cells change for each succeeding generation by the following rules:
a. A living cell dies of overcrowding in the next generation if it currently has 4 or more living neighbors.
b. A living cell dies of loneliness in the next generation if it currently has only 0 or 1 living neighbors.
c. An empty cell becomes a “birth” cell (becomes alive) in the next generation if it has exactly 3 living neighbors.
d. All other cells remain unchanged.
3) The new generation becomes the current generation and is displayed.
4) After displaying each new generation, ask the user if they wish to continue to the next generation or stop at this point.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132`` ``````#include #include #include #include #include using namespace std; void Ask(int, int); void F_Gen(int, int); void Cell(int, int); void Start_Again(int); const int M_Row (60); const int M_Col (60); int Gen = 0; bool I_Cell [M_Row + 2] [M_Col + 2]; bool L_Cell [M_Row + 2] [M_Col + 2]; int main() { int Row = 0; int Col = 0; // int Start = 0; time_t StopTime; do { do { Ask(Row, Col); F_Gen(Row, Col); /* Start_Again(Start);*/ I_Cell [Row][Col] = L_Cell [Row][Col]; } while (1); memcpy (I_Cell, L_Cell, (M_Row + 2) * (M_Col + 2) * sizeof (bool)); StopTime = time (0) + 3; while (time (0) < StopTime); } while (!_kbhit ()); cout << "Bye" << endl; } void Ask (int X, int Y) { cout << " Game Of Life " << endl; cout << "Enter the Number of Row (1 to 60): "; cin >> X; if ((X < 0) || (X > 60)) { cout << "Invalid Row" << endl; exit (0); } else if ((Y >=0 ) || (Y <= 60)) { cout << "Enter the Number of Column (1 to 60): "; cin >> Y; } else if ((Y < 0) || (Y > 60)) { cout << "Invalid Column" << endl; exit (0); } else if ((X < 0) || (X > 60) || (Y < 0) || (Y > 60)) { cout << "Invalid Number" << endl; exit (0); } else; } void F_Gen(int XY, int YZ) { int SN; memset (I_Cell, false, (M_Row + 2) * (M_Col + 2) * sizeof (bool)); memset (L_Cell, false, (M_Row + 2) * (M_Col + 2) * sizeof (bool)); do { for (XY = 1; XY <= M_Row; XY++) { for (YZ = 1; YZ <= M_Col; YZ++) cout << (I_Cell [XY] [YZ] ? '*' : ' ') << endl; } ++Gen; for (XY = 1; XY <= M_Row; XY++) for (YZ = 1; YZ <= M_Col; YZ++) { Cell(XY, YZ); } cout << "Would You like to Start the next generation (Y/N): "; cin >> SN; } while (SN == 'Y' && SN == 'y'); } void Cell(int W, int Z) { if (I_Cell [W][Z] == 1) { if ((I_Cell [W][Z - 1] == 1) && (I_Cell [W][Z + 1] == 1) && (I_Cell [W - 1][Z] == 1) && (I_Cell [W + 1][Z] == 1)) I_Cell [W][Z] == 0; else if ((I_Cell [W][Z - 1] <= 1) && (I_Cell [W][Z + 1] <= 1) && (I_Cell [W - 1][Z] <= 1) && (I_Cell [W + 1][Z] <= 1)) I_Cell [W][Z] == 0; else if (((I_Cell [W][Z - 1] == 1) && (I_Cell [W][Z + 1] == 1) && (I_Cell [W - 1][Z] == 1) && (I_Cell [W + 1][Z] == 0)) || ((I_Cell [W][Z - 1] == 1) && (I_Cell [W][Z + 1] == 1) && (I_Cell [W - 1][Z] == 0) && (I_Cell [W + 1][Z] == 1)) || ((I_Cell [W][Z - 1] == 0) && (I_Cell [W][Z + 1] == 1) && (I_Cell [W - 1][Z] == 1) && (I_Cell [W + 1][Z] == 1)) || ((I_Cell [W][Z - 1] == 1) && (I_Cell [W][Z + 1] == 0) && (I_Cell [W - 1][Z] == 1) && (I_Cell [W + 1][Z] == 1))) I_Cell [W][Z] == 1; else I_Cell [W][Z] == 0; } } //void Start_Again(int SA) //{ // cout << "Would you like to Start the Program Again (Y/N): "; // cin >> SA; // // if ((SA == 'Y') && (SA == 'y')) // system ("CLS"); // // else; //} ``````

for the output = The first screen looks like this
 ``` Game of Life Enter the Number of Row (1 to 60): 12 Enter the Number of Column (1 to 60): 12 Would You like to Start the next generation (Y/N): Y // Doesn't stop to ask again....It just continues. ```
Last edited on
Topic archived. No new replies allowed.