Ok, well this might get messy, but it might also help you find the problem yourself. For each line of code in your main, add a comment which explains the purpose of the line. It sounds to me like...