march of toads

hi, i have the code completed but it will not compile and run . i'm taking finals and i will need alot of spare time to fix this code. can anyone plz help me fix and run this code. any help is appreicated.







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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
 #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,toad, col, i ;

for (row = 0; row < ROWS;row ++)

{

for (col = 0; col < COLS+2;col ++)

{
    
    
    if(toad[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[rows-1][col]='b'
}

if(toads [row-2][col]=='.';
{
         
toads[rows-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,blacnk ;

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);
    }

    return 0;
}















Cane toads are an invasive species in Australia which are causing environmental havoc. The problem is that cane toads are poisonous and nearly all the Australian predators are susceptible to cane toad poisoning. Wherever the toads have reached they have caused a tremendous loss of native species like snakes which attempt to eat toads which look tasty to a snake. About 90% of the at risk populations are killed.

The goal of this assignment is to use a 2D array to represent a region of the earth which will start with one cell selected at random which will have 1 pair of cane toads. The array can be an array of enums where the enums are defined as NONE, BABIES, or ADULTS. The initial configuration will be all cells of the 2D array having value NONE. Then you would call the random function twice to get random integers. Use a random number mod the number of columns (plus one) to get a random column number and do the same to get a random row number. Set this cell's value to ADULTS. This will represent having at least 1 pair of adults who can propagate to neighboring cells.

Your program should then print the array and use getline to read a line of input. The purpose of the getline call is to allow the user to look at the array. I suggest having 20 rows and 50 columns in the array and using "." to represent NONE, "A" to represent ADULTS and "b" to represent BABIES.

After getting the input line the program should propagate to all cells with a NONE value a BABIES value if there is a neighboring cell with ADULTS. There will be 8 neighbors for all cells in the interior of the array. A significant programming simplification can be made by having the actual array be 2 rows and 2 columns larger - that means using a 22x52 array and then if your process rows 1-20 and columns 1-50 the processed cells will all be interior cells.

After changing some cells to BABIES, the array should be printed. Then you need to call a function to change all the BABIES to ADULTS and use getline again to wait until the user is ready to see the next step.

Your program should exit when all the interior cells (20*50 = 1000) are all ADULTS. At that point Australia will be toast.

At some point in execution it might be possible to view a region like this - or maybe it will look like some other common figure...

..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................bbb.............................
.................bbAbb............................
................bbAAAbb...........................
................bAAAAAb...........................
................bbAAAbb...........................
.................bbAbb............................
..................bbb.............................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
Last edited on
can anyone plz help me?
Sorry but i dont really understand you program, and what did you mean by fix here ? Is it algorithm error, or code if it is what is the error, i cant test your code myself because i'm on my phone right now
thank you for replying, its syntax errors so far if i'm correct. would you mind checking it, thank you
sorry about not adding the description to what this code is suppose to do.
Whats the error ? Its too much for my phone. You can click on the small gear icon on upper right of you code
In function 'bool full(char (*)[52])':
59:16: error: invalid types 'int[int]' for array subscript
59:28: error: expected ')' before ';' token
62:1: error: expected ';' before '}' token
80:1: error: a function-definition is not allowed here before '{' token
229:1: error: expected '}' at end of input
229:1: error: expected '}' at end of input
229:1: warning: control reaches end of non-void function [-Wreturn-type]
You're just missing afew character, like in line 59 you havent close if expression with )
okay, do you mind showing me how to close it and helping make the code compile right. sorry, i have been working on this code all day. my head is killing me.
Sorry if i on pc or laptop i'll help, but i'm not
okay, thanks for your help though. any help is appreicated
would you mind walking me through what to do to make it compile please if that is okay?
can anyone help me finish my code. its just a few errors to fix thats all. any help will be appreciated
Topic archived. No new replies allowed.