An important way to ensure your code is correct is to write tests for each individual unit of code you write; for each individual method. Chances are you've started to do so; you write a method, and then verify that it works, probably calling it from main; the problem with this is that, when you test the next method, you delete the previous tests, and, if you ever change the method you don't have those tests anymore.