Link to home
Start Free TrialLog in
Avatar of hackermen5
hackermen5Flag for United States of America

asked on

Compound interest .... !!!

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Out of interest (no pun intended) why would you want to do it recursively?
I reckon it says to as part b of the homework... ;-)
SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 )

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.
>  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?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dannin
Dannin

     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;
      }
Dannin, your balance will always remain zero.
Also, by the way, why is balance supposed to multiplied by (( 1 + i ) ^ n) 'n' number of times?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well isn't it the way the person who asked the question wanted it?
> Tell your teacher that recursion should be avoided

except if you're learing about recursion :)
Then an example that needs recursion should be given
An (familiar) problem that can be solved with recursion is just as suitable.
Avatar of hackermen5

ASKER

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 .....
By the way, why did you accept my comment as an assist? (I was still waiting to assist after getting some comments from you :-) )