# these code is how to find (the new mortgage values of a house), but I'm having troubles changing it to find (how long it will take to pay off a house).

3 visualizzazioni (ultimi 30 giorni)
Todd Wyzkiewicz il 9 Apr 2020
Commentato: James Browne il 10 Apr 2020
disp('I can tell you how much you''ll have to pay for your house.')
disp([' '])
pv=input('What was your original mortgage value? ');
rate=input('What is the yearly interest rate on your home? ');
pmt=input('What is your mounthly payments? ');
nper=input('How many monthly payments have you made so far? ');
m = (rate/100)/12;
nper = 10*12;
current_balance = 1:nper;
for loop = 1 : nper
pv = pv*(1+m)-pmt;
current_balance(loop) = pv;
fprintf('The current balance after %d periods (out of %d) is %.2f\n', ...
loop, nper, current_balance(loop));
end
All of the variables and the equation are still used, but Im thinking that I just need to change the fprintf line, but this is suppose to be in a while loop. I'm not sure if that changes much of the code
##### 9 CommentiMostra 7 commenti meno recentiNascondi 7 commenti meno recenti
Todd Wyzkiewicz il 10 Apr 2020
I acctually have to trun it in tonight so just don't worry about it. thanks though.
Walter Roberson il 10 Apr 2020

Accedi per commentare.

### Risposte (1)

James Browne il 10 Apr 2020
Hello, I think I have found a solution for you, or at least something close:
disp('I can tell you how much you''ll have to pay for your house.')
disp([' '])
pv=input('What was your original mortgage value? ');
rate=input('What is the yearly interest rate on your home? ');
pmt=input('What is your mounthly payments? ');
nper=input('How many monthly payments have you made so far? ');
m = (rate/100)/12;
nper = 10*12;
current_balance = 1:nper;
loop = 0;
while pv > 0
pv = pv*(1+m)-pmt;
loop = loop + 1;
current_balance(loop) = pv;
end
fprintf('It will take %d periods to pay off the loan\n',loop);
Hope this helps =)
##### 4 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Todd Wyzkiewicz il 10 Apr 2020
Sick! Thanks brother!
James Browne il 10 Apr 2020
Oh yea, good catch!

Accedi per commentare.

### Categorie

Scopri di più su Programming in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by