Solved

Compound interest .... !!!

Posted on 2003-12-11
18
731 Views
Last Modified: 2007-12-19
hi everyone, i need help on that question ....

what is the compound interest formula if i'm using 'i' for the rate and 'n' for the numbers of years ???

i already wrote two functions but they're not working !!!!

//============================================
// First one
//========

    public float Total(float i,int n)            //Savings -> return balance after n years and i interest
    {
        for(int count=0; count<n; count++)
        {
            Balance *= Math.pow(( 1 + i ), n);
        }
        return Balance;
    }
//================

// Second one
//========

    public float Total(float i,int n)            //Savings -> return balance after n years and i interest
    {
        return Balance *= Math.pow(( 1 + i ), n);
    }
//============================
i don't know what one is the correct one .... i'm not a business major :P


and if by any chance ..... could anyone tell me how to do it in the recursive way !!!

thankz
0
Comment
Question by:hackermen5
  • 5
  • 4
  • 3
  • +3
18 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9919687
Out of interest (no pun intended) why would you want to do it recursively?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9919717
I reckon it says to as part b of the homework... ;-)
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 100 total points
ID: 9919805
Compound Interest is calculated like:

public calculateCompoundInterest( double rate, double period )
{
    balance = balance * Math.pow( 1+rate, period ) - balance ;
}

Make sure your "balance" variable is a double...(not an int)

Tim
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 86

Expert Comment

by:CEHJ
ID: 9919821
Tell your teacher that recursion should be avoided where it's not necessary (as it is not here;-))

The formula for simple interest is:   F  =  P ( 1 + R / N ) ^ ( N * T )

             Where :  F   =  final amount
                           P   =  initial amount
                           R   = interest rate
                           N   = number of compounding periods
                           T   = Time ( in years )

0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9919966
More importantly, the recursive function that he's written will go on looping forever as there's no stopping condition.

BTW, hackermen5, this is not a place to tell you the correct formula :-) we can help you with the coding/ implementation if you face problems.

I guess he needs recursion in computing the value of (1 + R/N) ^ T.... (for computing the exponential value). Strange way.

Mayank.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9920030
>  More importantly, the recursive function that he's written will go on looping forever as there's no stopping condition.

Which one do you think is recursive?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9920031
;-)
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 50 total points
ID: 9920120
public float Total(float i,int n)            //Savings -> return balance after n years and i interest
    {
        return Balance *= Math.pow(( 1 + i ), n);
    }
//============================

Sorry, I thought I saw a call to Total () instead of pow :-) didn't read it completely.... thought that the first was non-recursive and the second recursive.

Anyways, he's still not told us why he needs the recursion.
0
 
LVL 2

Expert Comment

by:Dannin
ID: 9920240
     public float Total(float i,int n)  
      {
          float balance=0;
          for(int count=0; count<n; count++)
          {

                  balance*= Math.pow(( 1 + i ), n);
          }
          return balance;
      }
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9920283
Dannin, your balance will always remain zero.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9920299
Also, by the way, why is balance supposed to multiplied by (( 1 + i ) ^ n) 'n' number of times?
0
 
LVL 2

Accepted Solution

by:
Dannin earned 100 total points
ID: 9920301
Opps I'm too used to addition lol

    public float Total(float i,int n)  
     {
         float balance=1;
         for(int count=0; count<n; count++)
         {

               balance*= Math.pow(( 1 + i ), n);
         }
         return balance;
     }
Here u go
0
 
LVL 2

Expert Comment

by:Dannin
ID: 9920314
Well isn't it the way the person who asked the question wanted it?
0
 
LVL 92

Expert Comment

by:objects
ID: 9923823
> Tell your teacher that recursion should be avoided

except if you're learing about recursion :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9923910
Then an example that needs recursion should be given
0
 
LVL 92

Expert Comment

by:objects
ID: 9924061
An (familiar) problem that can be solved with recursion is just as suitable.
0
 
LVL 1

Author Comment

by:hackermen5
ID: 9924836
i'm sorry uys ... but my teaher is not that nice to give us an example of recursion .... i didn't even understand the recursion concept yet .....

anyway ..... thanks for ur help guys .....
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9925774
By the way, why did you accept my comment as an assist? (I was still waiting to assist after getting some comments from you :-) )
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Should localization be done inside spring controller 5 26
maven module vs maven project 3 23
Facing this issue for maven proxy setting 2 12
printf performancy 11 43
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question