Please post the code's output that shows the problem.
What values are not being computed like you expect?
Give some examples of the input to the program and the program's output.