while loop statement errors

4 views (last 30 days)
Todd Wyzkiewicz
Todd Wyzkiewicz on 9 Apr 2020
Commented: Todd Wyzkiewicz on 10 Apr 2020
disp('I can tell how long you''ll have to pay for your house.')
disp([' '])
pv=input('What was your present mortgage value? ');
rate=input('What is the yearly interest rate on your home? ');
pmt=input('How much are your mounthly payments? ');
fv=input('What is your future disired mortgage value? Hopefully its 0. ');
m = (rate/100)/12;
while nper>0
nper = pv*(1+m)-pmt;
current_balance = 1:nper;
loop = 1 : nper;
current_balance(loop) = nper;
fprintf('It should take %d periods (out of %d) to get your payments to %.2f\n', ...
loop, fv, current_balance(loop));
end
  20 Comments
Walter Roberson
Walter Roberson on 10 Apr 2020
I repeat my recommendation to run the calculation first to get all of the balances and then display the output once you know how many there are.
(By the way, balance should never go negative. It is acceptable to pay to below the desired future mortage value, but not below 0.)
Todd Wyzkiewicz
Todd Wyzkiewicz on 10 Apr 2020
Your right the but the last payment will just be less that the 1200 in this instance. I acctually dropped the priced and ketp the payment amount.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!