Have you debugged it step by step? Try setting a breakpoint where you think
(or want) the program to terminate. Also, set the debugger so it shows you
how values change with each executable step....