
-----------------------------------
roer
Sat Dec 06, 2003 7:28 pm

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  :oops: 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

-----------------------------------
AsianSensation
Sat Dec 06, 2003 11:36 pm


-----------------------------------
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
Sat Dec 06, 2003 11:44 pm


-----------------------------------
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
Sat Dec 06, 2003 11:56 pm


-----------------------------------
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
Sun Dec 07, 2003 2:42 pm


-----------------------------------
Thanks for all your help AsainSensation :) The only thing I still dont understand is how the compounding period works. Like when the user enters a compounding period of quarterly, it means that the user will collect intrest every 3 months (4 times a year). I don't understand how to make the program do that. How would I make it do that?

Would I have to set up a counter and use the mod function or something along those lines?

counter := counter + 1
if counter mod 3 = 1 then
interest := formula here
else
interest := 0

Should it be something along those lines?

EDIT : Here's some bits Asain  :) +10

-----------------------------------
AsianSensation
Sun Dec 07, 2003 5:07 pm


-----------------------------------
to compound more than once per year, just input it into the formula, here is an example.

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
Sun Dec 07, 2003 5:48 pm


-----------------------------------
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:

Month       Investment        Interest
1                    7.00              .00
2                    7.00              .00
3                    7.00              .40
4                    7.40              .00The 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
Sun Dec 07, 2003 7:35 pm


-----------------------------------
wtf? azn dont be like mazer!! take those frigging bits back!!!
+raondom amount of bits

-----------------------------------
roer
Sun Dec 07, 2003 8:13 pm


-----------------------------------
Please? Anyone want to help   :(

-----------------------------------
roer
Sun Dec 07, 2003 11:02 pm


-----------------------------------
All right this is my final plea  :(

-----------------------------------
AsianSensation
Mon Dec 08, 2003 12:17 am


-----------------------------------
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:

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
