while loop statement errors

1 visualización (últimos 30 días)
Todd Wyzkiewicz
Todd Wyzkiewicz el 9 de Abr. de 2020
Comentada: Todd Wyzkiewicz el 10 de Abr. de 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 comentarios
Walter Roberson
Walter Roberson el 10 de Abr. de 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 el 10 de Abr. de 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.

Iniciar sesión para comentar.

Respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by