calculate Future value in iPhone

2019-08-27 12:38发布

问题:

Will the following function for calculating Future value based on present value, interest rate and time period work in iphone?

-(float) calcFV: float pv: float interest_rate: float time
{
   float fv, pv, interest_rate, t;

   //pv = 200000.0; // present value
   //i  = 0.012;    // interest rate (1.2%)
   //t  = 5.0;      // time period

   fv = pv * pow (1.0 + interest_rate, time);
   return fv;

}

回答1:

Yes, and no!

Despite the fact that your formula is correct, you are declaring pv and interest_rate, as well as passing them in as parameters.

Remove the declarations:

-(float) calcFVFromPresentValue: (float) pv interest_rate: (float) interest_rate time: (float) time
{
    float fv;

    //pv = 200000.0; // present value
    //i  = 0.012;    // interest rate (1.2%)
    //t  = 5.0;      // time period

    fv = pv * pow (1.0 + interest_rate, time);
    return fv;

}

Incidentally, your .h file should now have this:

-(float) calcFVFromPresentValue: (float) pv interest_rate: (float) interest_rate time: (float) time;


回答2:

Considering the equation is current * (1.0+interest)^time, yes it will.