
-----------------------------------
battleroyale
Mon May 02, 2005 4:41 pm

help with for statements
-----------------------------------
ok...for school, i need to make a mortage thing. Starting off with 120000 at 10.75% interest a year, i need to figure out when it will go down to zero if i pay 24000 a year. My teacher wants it like this

Year    Beginnnig Balance   Interest    Payment    Year End Balance


this is what  i did so far

var c:real:=120000

const it:real:=0.1075
const pay:int:=24000

for i:1..10     %how do i make it so it ends when c=0?

put i, " ", c:5:2, "   " , c*it:5:2, "   ", pay:5:2, "  ", (c+(c*it)-pay:5:2

c:=c-(c*it)

end for


how do i make it so the for statement ends when c=0?

-----------------------------------
AsianSensation
Mon May 02, 2005 5:10 pm


-----------------------------------
use the exit statement.

exit when c = 0

-----------------------------------
battleroyale
Mon May 02, 2005 5:13 pm


-----------------------------------
If you meant something like this 
var c:real:=120000


const it:real:=0.1075
const pay:int:=24000



for i:1..100  

put i, " ", c:5:2, "   " , c*it:5:2, "   ", pay:5:2, "  ", (c+(c*it))-pay:5:2
c:=c-(c*it)

exit when c=0

end for


it doesnt work...it might be becuase of some eqaution but i dont know why. Help

-----------------------------------
mike200015
Mon May 02, 2005 5:56 pm


-----------------------------------
it ran fine?

your for loop goes from 1 to 100, at 100, c only = 1.55 so there is no need for your exit when c = 0

-----------------------------------
c0bra54
Mon May 02, 2005 6:22 pm


-----------------------------------
yeh but it ahs to goto zero, so just use maxint or anynumber lol, and then exitwhen c = 0 and makesure you include the last payment!

-----------------------------------
battleroyale
Mon May 02, 2005 6:34 pm


-----------------------------------
THis is what i did

% var c : real := 120000
% 
% 
% const it : real := 0.1075
% const pay : int := 24000
% 
% put "Year", "      ", "Beginning", "    ", " Interest", "     ", "Payment", "      ", "Year End"
% put "           ", "Balance", "       ", "Charged", "                   ", "Balance"
% put ""
% for i : 1 .. 7
% 
%     put " ", i, "      ", c : 10 : 2, "   ", c * it : 10 : 2, "    ", pay : 10 : 2, "     ", (c + (c * it)) - pay : 10 : 2
% 
%     c := c + (c * it) - pay
% 
%     if c 