Re: Need help with my logic



Patricia Shanahan wrote:
See http://home.earthlink.net/~patricia_shanahan/debug/ for my favorite
approach.


I didn't read all the way through that, so sorry if I missed this, but there's two things I thought I'd mention, since the OP says she couldn't understand the link.

1. Hand Execution

Learn how to execute your programs by hand. This is probably the best thing you can ever learn if you are a programmer.

Print out your program and go through it line by line. Write variable names on a piece of paper as you encounter them, and write their value next to them. When the variable changes value later, cross out the old value and write the new one next to it on the right.

This will solve a lot of problems, and also make you much better about designing programs in the future.

2. Divide and Conquer

Once your programs get very large, you really can't hand execute the whole thing any more. Learn how to divide your program into chunks (modules, classes, methods, subroutines, etc....) Then make sure each chunk is working correctly before putting them all together. This will save you a lot of time when you write (and debug) large programs.

Also see "Unit Testing."


Ok, good luck.
.