Help Please

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.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include <memory.h>
#include <time.h>
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.