You've answered your own question, no the program is not correct if you're not getting the result you want.

Now as to the actual problem you'll need to tell us what result your program is...