Filter löschen
Filter löschen

while loop statement errors

2 Ansichten (letzte 30 Tage)
Todd Wyzkiewicz
Todd Wyzkiewicz am 9 Apr. 2020
Kommentiert: Todd Wyzkiewicz am 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 Kommentare
Walter Roberson
Walter Roberson am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by