while loop statement errors

조회 수: 3 (최근 30일)
Todd Wyzkiewicz
Todd Wyzkiewicz 2020년 4월 9일
댓글: Todd Wyzkiewicz 2020년 4월 10일
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
Walter Roberson
Walter Roberson 2020년 4월 10일
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 2020년 4월 10일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by