"Germs" – a C++ assignment, what am i doing wrong? [closed]

You are overwriting the array in front of you.
For example with this input:

1 0
0 0

your program will answer 1 instead of 2.
The reason is, that after you process the top left corner, your array looks like this:

1 1
1 0

Which is correct, but in the same cycle of the top level while
you also simulate the bottom left corner, which spreads to the bottom right and finishes the simulation immediately.

One sollution to this is to use two arrays, reading from one, writing to the other, and swap them at the end of each cycle.

Browse More Popular Posts

Leave a Comment