help with for statements
Author |
Message |
battleroyale
|
Posted: Mon May 02, 2005 4:41 pm Post subject: 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
code: | 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? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
AsianSensation
|
Posted: Mon May 02, 2005 5:10 pm Post subject: (No subject) |
|
|
use the exit statement.
|
|
|
|
|
|
battleroyale
|
Posted: Mon May 02, 2005 5:13 pm Post subject: (No subject) |
|
|
If you meant something like this
code: | 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
|
Posted: Mon May 02, 2005 5:56 pm Post subject: (No subject) |
|
|
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
|
Posted: Mon May 02, 2005 6:22 pm Post subject: (No subject) |
|
|
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
|
Posted: Mon May 02, 2005 6:34 pm Post subject: (No subject) |
|
|
THis is what i did
code: |
% 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 <= 24000 then
% put " ", i + 1, " ", c : 10 : 2, " ", c * it : 10 : 2, " ", c : 9 : 2, " ", c - c : 4 : 2
% end if
% end for
|
works out fine too....uncomment it first though |
|
|
|
|
|
|
|