Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 help with for statements
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
battleroyale




PostPosted: 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
Sponsor
sponsor
AsianSensation




PostPosted: Mon May 02, 2005 5:10 pm   Post subject: (No subject)

use the exit statement.

code:
exit when c = 0
battleroyale




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: