Why my calculation is not working properly?