march of toads error

Hi, my code will not compile correctly. i have everything written and in order, there are only 2 errors but i don't know how to fix them. any help will be greatly appreciated.


here are the errors:

113 a function-definition is not allowed here before '{' token
113 expected `,' or `;' before '{' token
113 At global scope:
174 expected declaration before '}' token






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
 #include <iostream>
#include <cstdlib>

using namespace std;

const int ROWS = 20;
const int COLS = 50;

void initialize ( char toads[][COLS+2] )
	{
		int row, col;
		//  Fill all 22 rows and 52 cols with '.'
		
		for (row = 0; row < ROWS;row ++)
			{
				for (col = 0; col < COLS+2;col ++)
					{
						toads [row][col]= '.';
					}
			}
		
		row=rand()%(row+1);  //  Select a random row number using rand() mod the number of rows plus one
		
		col=rand()%(col+1);  //  Select a random column number using rand() mod the number of columns plus 1
		
		toads[row][col]='A'; //  Place an 'A' (Adult) in location (row,col) of the toads array
		
	}

bool full ( char toads[][COLS+2] )
	{
		//  Return true if all 20x50 interior cells are Adults
		
		int row, col, i ;
		
		for (row = 0; row < ROWS;row ++)
			{
				for (col = 0; col < COLS+2;col ++)
					{
						if(toads[row][col]!= 'A');
							{
								i++;
							}
						
						if ( i==0)
							{
								return true;
							}
						
						else return false;
							{
								void propagate ( char toads[][COLS+2] );
							}
						//  For all 20 rows and 50 columns of interior cells
						//  Convert any neighboring '.' cells to 'b'  (baby)
						
						int row, col;
						
						for (row = 0; row < ROWS;row ++)
							{
								for (col = 0; col < COLS+2;col ++)
									{
										if (toads[row-1][col-1]=='A');
											{
												if (toads[row][col]=='.');
													{
														toads[row][col]='b';
													}
												
												if (toads [row-1][col]=='.');
													{
														toads[row-1][col]='b';
													}
												
												if(toads [row-2][col]=='.');
													{
														toads[row-2][col]='b';
													}
												
												if (toads [row-2][col-1]=='.');
													{
														toads[row-2][col-1]='b';
													}
												
												if (toads[row-2][col-1]=='.');
													{
														toads [row-2][col-1]='b';
													}
												
												if (toads[row-1][col-2]=='.');
													{
														toads[row-1][col-2]='b';
													}
												
												if (toads[row][col-2]=='.');
													{
														toads[row][col-2]='b';
													}
												
												if (toads[row][col-1]=='.');
													{
														toads[row][col-1]='b';
													}
												
												if (toads[row][col]=='.');
													{
														toads[row][col]='b';
													}
												
											}
										
										void maturate ( char toads[][COLS+2] )
											{
												int row, col;
												
												for (row = 0; row < ROWS;row ++)
												//  For all 20 rows and 50 columns of interior cells
												//  Convert any 'b' cells (baby) to 'A' (Adult)		
													{
														for (col = 0; col < COLS+2;col ++)
															{
																if(toad[row][col]=='A';
																	{
																		toad[row][col]='b';
																	}
															}
														
														void print ( char toads[][COLS+2] )
															{
																//  Print all 20 rows and 50 columns of the toads array
																
																int row, col,blank ;
																
																for (row = 0; row < ROWS;row ++)
																	{
																		for (col = 0; col < COLS+2;col ++)
																			{
																				cout<<toads[row][col];
																				
																				if(col==50);
																					{
																						cout<<endl;
																					}
																						
																						getline(cin,blank);
																						//  Use getline to force the user to press return
																					}
																				
																				int main()
																					{
																						char toads[ROWS+2][COLS+2];
																						//  Seed the random number generator with the number of seconds since the
																						//  beginning of the UNIX epoch (Jan. 1, 1970).
																						srand(time(NULL));
																						
																						//  Fill the toads array with dots and one randomly placed Adult toad
																						initialize ( toads );
																						while ( !full(toads) )
																							{
																								propagate(toads);
																								print(toads);
																								maturate(toads);
																							}
																				}
																							}
																					}
																			}	
																	}
															}
													}
											}
									}
							}
	}
system("PAUSE");return 0;
}
}

You cannot define a function inside another function.
oh okay, how do i fix it?
Don't define a function inside another function?

1
2
3
4
5
6
7
8
9
void f()
{
    // body of function
}

void g()
{
   // body of function.  Notice the definition of g is not in the body of f.
}


Topic archived. No new replies allowed.