Right-click on the left margin at the first line in main(), and insert break point.
Then do run->debug program.
Then hover over the { } icons which appear to figure out which is "step into", "step over", "step out" etc.
Use these to step through your code one line at a time.
At every step, examine your variables to see if they contain what you expect.
When actuality != expectation, that's a BUG.