Interest Calc  Homework Question
Author 
Message 
roer

Posted: Sat Dec 06, 2003 7:28 pm Post subject: Interest Calc  Homework Question 


I need help finishing off my interest calculatour for CompSci class, we've been doing Turing for about 3 weeks now and I'm kind of disorriented I cant figure out how to code a part of the program so that when the user enters a certain string it will display a certain prinicpal when the loop goes through every 3 times. So I would have to set up a counter rite?
It would have to work like this though to give you an idea:
month intrest
1 .00
2 .00
3 .63 (whatever intrest is)
4 .00
How would I go about making it skip like that? Its all I need to finish this program =)
Thanks beforehand






Sponsor Sponsor



AsianSensation

Posted: Sat Dec 06, 2003 11:36 pm Post subject: (No subject) 


I don't get how the interest could skip like that.........but anyways, here goes what I could make out of your question.
I assume you start by asking the user to input some principle, some rate of interest and how many years they want to store it for, and how many times it compounds in a year. Then just input it into the formula (I'm assuming you know it) and run it through a for loop. The interest for each month would be whatever value you get subtract by the value you got from the last time the loop was run. So you need a temporary varible to hold last month's total.






roer

Posted: Sat Dec 06, 2003 11:44 pm Post subject: (No subject) 


code:  if compound_period = "S" or compound_period = "s" then
for s : 1 .. term
interest := cash_investment * interest_rate / 200
cash_investment := cash_investment + interest
total := cash_investment + interest
put s : 3, cash_investment : 30 : 2, interest : 25 : 2, total : 20 : 2
end for 
That is part of my code for calculating how the table will be put out. I basically have it like this 3 more times except they are for different values.






AsianSensation

Posted: Sat Dec 06, 2003 11:56 pm Post subject: (No subject) 


or you could just use this formula and plug in numbers while you run a for loop.
Total = P(1 + r/n)^(Y*n)
where
P is the principle
r is the rate (in decimal form, like 0.25 would be 25% interest)
n is the amount of times it compounds in one year
Y is the amount of years






roer





AsianSensation

Posted: Sun Dec 07, 2003 5:07 pm Post subject: (No subject) 


to compound more than once per year, just input it into the formula, here is an example.
code:  var P, r : real
var Y, n : int
P := 100
r := 0.1
Y := 5
n := 4
put P * (1 + r / n) ** (Y * n) /*compounding quarterly*/
put P * (1 + r) ** (Y) /*compounding once per year*/ 
the first output would be compounding quarterly for 5 years
the second output would be compounding annually for 5 years
btw, I really don't need bits, I've done all the customizing I could with the name, so you can have them instead.
give roer bits






roer

Posted: Sun Dec 07, 2003 5:48 pm Post subject: (No subject) 


Thanks for the code and bits Asain Theres still a problem in my program though. I have to make it so that for every month it shows what your investment and interest is. So it would look like:
code: 
Month Investment Interest
1 7.00 .00
2 7.00 .00
3 7.00 .40
4 7.40 .00  The thing is I dont know how to make it like that. I can calculate all the compounding periods but this I cant do. I can get the colums and all by using fields, but I have no idea how to make it so that it goes every 3 months.






Andy

Posted: Sun Dec 07, 2003 7:35 pm Post subject: (No subject) 


wtf? azn dont be like mazer!! take those frigging bits back!!!
+raondom amount of bits






roer

Posted: Sun Dec 07, 2003 8:13 pm Post subject: (No subject) 


Please? Anyone want to help






roer

Posted: Sun Dec 07, 2003 11:02 pm Post subject: (No subject) 


All right this is my final plea






AsianSensation

Posted: Mon Dec 08, 2003 12:17 am Post subject: (No subject) 


I'm helping, I'm helping. Was just too busy watching TV, sorry bout that.
Anyways, I really don't get why the interest jumps like that. Maybe it depends on the exact time that it compounds? I mean, like you said, if it compounds quarterly, then every 3 month, it should give you some interest. Well, just plug it into the formula.
in the end it would be something like this:
code:  var Y, n, total, temptotal : int
Y := 1
n := 4
for rep : 1 .. Y
if rep mod (12 / n) = 0 then
%calculate total here
end if
put "Month Investment Interest"
put rep, " ", total, " ", total  temptotal
temptotal := total
end for 







