It sounds like you need to debug your program. You do this be either stepping through your program with a debugger, or adding print statements, or walking through it by hand with a piece of paper and...