But it's an if statement, if i put ; at the end of the if then it will ignore everything else. I'm not getting an error on line 27 in my compiler. Im using Dev c++ if youre wondering.
-- i just tried putting ; at the end of the if statement, i get an error because the else isn't paired with an if now.
edit; also for some reason the spacing on here is really bad, even though its not the same way in my compiler. So i tried manually fixing it the best way I could since copying + pasting keeps giving it some extra and weird spaces in random places.
> for some reason the spacing on here is really bad
you are mixing tabs and spaces
while (loanAmount != 0)
you'll have precision issues, instead of 0 you may reach a really small number but your loop will keep going
change it to while(loadAmount > 0)
switched it to that, but when I run it i still get the same problem where it doesn't tell me how many months it will take, it just sits there and blinks at me taunting me, daring me to put my fist through the monitor.
The reason your program never ends and never prints out the final result is because your do-while loop never ends. You are looking for loan amount == 0.0, but that never occurs because of 1 of 2 reasons.
First, you are reducing payment every time through the while loop. That means the monthly payment is constantly being reduced. You really want to change payment in lines 32 and 33 to "principalReduction".
Second, in line 33 you only want to subtract principalReduction from loanAmount if it is actually less than loanAmount. Otherwise, just set loanAmount to 0.0.
You keep decreasing the payment. Eventually it drops to zero, then it becomes negative, which means you start adding to the loan amount instead of subtracting from it.