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

Username:   Password: 
 RegisterRegister   
 Interest Calc - Homework Question
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
roer




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




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




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




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




PostPosted: Sun Dec 07, 2003 2:42 pm   Post subject: (No subject)

Thanks for all your help AsainSensation Smile 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?

code:
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 Smile +10
AsianSensation




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




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

Thanks for the code and bits Asain Smile 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




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




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

Please? Anyone want to help Sad
roer




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

All right this is my final plea Sad
AsianSensation




PostPosted: 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
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  [ 11 Posts ]
Jump to:   


Style:  
Search: