Your program has a bug and it is crashing. Usually this is the part where folks point out that this forum isn't meant for help with programming itself, but my recommendation is to enable debugging symbols for your project (Project>Build options) or for all projects (Settings>Compiler). Then do a full Rebuild (Build>Rebuild) of your project and run your program through the debugger (Debug>Start). When the program crashes, Codeblocks will display the line in your code where the crash occurred and you can troubleshoot from there (ie. add watches to see the values of different variables). You can also set breakpoints so that execution of your program stops at specific places, optionally only when certain statements are true. You can also trace through the program line by line if you want. The debugger is an immensely helpful tool and I use it all the time, all programmers should, because it's unavoidable that humans write flawed code.