Can you post the output from the program that shows what you are talking about? Add some comments where the output is not what you want.

One problem I see in the code is using == to compare...