What does the code do? What exactly do you expect it to do? Where exactly (what line number) does the execution of the program differ from what you expect?

I recommend stepping through this with a...