Help!

I need quite a bit of help... I know one problem that has came up with my program as it is now is using a while loop for the choice, and it will loop infinitely, what type of loop or should i can this to a switch statment with cases. and also i need to be pointed in the right direction for the arrays with in the program. I need to initialize the array to blank spaces then for each selection a different starting shape will be given. I set the blank space to a '&' just to see if the array would fill up and it does not. and mind you i am only currently working on the choice=1. thanks for any help in advance, and sorry if i wasn't too clear...

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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
 #include <iomanip>

#include <iostream>

#include <cstdlib>

#include <string>

#include <cmath>

using namespace std;


int main()
{	//Create variables for dead and alive cells

	char alive ('*');

	char dead (' ');

	//create arrays and boundries

	const int nrows(25);

	const int ncols(25);

	char world[nrows][ncols]={"&"};

	char gen1[nrows][ncols];

	char gen2[nrows][ncols];

	//Create varaibles for menu choice

	int choice;

	int generations;

	//Explanation of program
	cout	<< " \tYou are about to play The Game of life!\n"
		<< " \t=======================================\n\n"
		<< " The game consists of cells that are occupied by organisms.\n"
		<< " A cell that is occupied by an organism will be represtented \n"
		<< " by a * if it is living and a blank space if it is dead. \n\n"
		<< " -----------------------------------------------------------\n"
		<< " The rules of the game are: \n\n"
		<< " 1. If an organism has zero of one neighbor it dies of\n"
		<< " loneliness. If it has more than three neighbors it dies\n"
		<< " of overcrowding.\n\n"
		<< " 2. If and empty cell has three living organisms around it, a\n"
		<< " new organism is born.\n\n"
		<< " 3. Births and deaths are instantaneous and occur at the \n"
		<< " changes of generation. A organism dying may help cause birth, \n"
		<< " but a newborn organism cannot resurrect a dying organism, \n"
		<< " nor will a organisms death prevent the death of another. \n\n"
		<< " -----------------------------------------------------------\n"
		<< endl;

	//Explanation of starting orgranisms

	cout << " You will have four choices of initial population.\n\n"
		<< " Choice 1 will create a basic row of organisms.\n That will look like: \n\n"
		<< " * * *\n\n"
		<< " Choice 2 will create a square of organisms.\n That will look like: \n\n"
		<< " * *\n"
		<< " * *\n\n"
		<< " Choice 3 will create an arrow pattern of organisms.\n"
		<< " That will look like: \n"
		<< " * * *\n"
		<< "     *\n"
		<< "   * \n\n"
		<< " Choice 4 will randomly create organisms anywhere in the game.\n\n"
		<< " Choice 5 give you the option to exit if you do not want to play.\n\n"
		<< endl;

	//Create Menu

	cout << "-----------------Menu of Choices------------------\n";

	cout << "==================================================\n";

	cout << " 1 - Three Cells occupied in a straight line.\n";

	cout << " 2 - A square of four cells.\n";

	cout << " 3 - A half Arrow pattern with 5 alive cells.\n";

	cout << " 4 - Randomly filled filled alive or dead cells.\n";

	cout << " 5 - Exit the program. \n";

	cout << "\n" << endl;

	cout << " Enter your choice and press return: ";

	cin >> choice;

	cout << "\n You have entered choice: " << choice << "\n\n" << endl;

	if ( choice>0 && choice<5)
	{	cout	<< " Please eneter the number of generations you would like "
	<< " to simulate ";

	cin		>> generations; 

	cout	<< "\n You want to simulate " << generations << " generations!\n" << endl;
	}
	if ( choice==0 || choice<0 || choice>5)
	{	cout << " You have entered an invalid choice.\n" << endl;

	cout << " The game will now exit.\n" << endl;

	system ("pause");

	return 0;
	}

	//Loop to use choices and amount of generations user would like to play

	while(choice==1)
	{	//variables

		int i, j;

		//for loop to set simple row cell start ***
		for ( i=0 ; i<1	; 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;
		
		}
	choice=99;
	}

	while(choice==2)
	{	//variables

		int i,j;

		//create square of organisms

		for (i=0 ; i<nrows ; i++)
		{ 
			for (j=0 ; j,ncols ; j++)
			{	
				world[1][1]=world[1][2]=world[2][1]=world[2][2]=alive;
			}
		}

	}

	while(choice==3)
	{	//variables

		int i,j;

		//create arrow of organisms

		for (i=0 ; i<nrows ; i++)
		{ 
			for (j=0 ; j,ncols ; j++)
			{	
				world[1][1]=world[1][2]=world[1][3]=world[2][3]=world[3][2]=world[3][3]=alive;
			}
		}

	}
	while(choice==4)
	{
	}
	while(choice==5)
	{ cout	<< " You have chosen to exit the program!\n\n"
	<< " Good Bye!\n" << endl;

	system ("pause");

	return 0;
	}


	system ("pause");

	return 0;
}
This
1
2
3
	while(choice==4)
	{
	}

is indeed an infinit loop.:)

I know one problem that has came up with my program as it is now is using a while loop for the choice, and it will loop infinitely, what type of loop or should i can this to a switch statment with cases.

What do you want it to do? Do you want it loop, so that the code within the loop repeats itself? Or do you want it to make a single one-time decision?
sorry it's taken so long to get back to you, but i need it to make a single one time decision. I tried using a switch and cases but it would not run
the program is suppose to create an initial shape of ***'s in anrray depending on what the user chooses in the menu. Then it goes through "generatations" to see if neighboring cells live or die, according to what cells are occupied or not occupied. hope that paints a better picture of what im trying to accomplish
Topic archived. No new replies allowed.