Edit:
See my comments below about how to do this better.
I am not sure if I am using an IDE; I am making my codes on Linux with something called Terminal. |
OK, so you compile by entering a g++ command in the shell (the terminal). So you can use gdb from the command line. Check out this article on how to use it. You should also read the gdb man page. A man page is a "Manual Page". type
man gdb from the shell command line.
An IDE is a "Integrated Development Environment" - it consists of at least an editor, a compiler, and debugger, plus other tools.
It is very good that you are using the command line, because you will learn a lot doing that. However, I think some things are really tough - you can get more done with an IDE. The debugger being much easier to use in the IDE is a good example. The danger is not to get addicted to the IDE without understanding how it all works. So take a look to see how the IDE does compilation & linking & make, then go back a find out what all the options mean. Also check out the gcc man page.
I would highly recommend using more functions - it will help you see the logic in your code as well as other benefits. The other rule is that code should be easy for others to understand - in the real world, code is written by someone, then maintained or looked at by lots of other people. Using functions is one way to help achieve this.
I think there is an easier way to count neighbours of cells. Limit the processing , so that it never goes out of bounds of the main array - keep 1 row & col in from the edge. That is from [1][1] to [ArrayHeight-1][ArrayWidth-1]. The start position is always [Row-1][Col-1] from the main array, and you use a nested for loop that checks a 3 by 3 chunk of the main array - excluding the position that corresponds to the cell which is having it's neighbours counted.
I think that could all be done in about 10 lines of code.
You could also have an array of structs instead of 2 arrays. The struct stores the attributes of each cell like number of neighbours. This is good because it is easily scalable to add extra info.
See how you go with all that - good luck :)