Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
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

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

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

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?

 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 +10
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)

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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 11 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: