calculate Future value in iPhone

2019-08-27 11:56发布

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;

}

2条回答
在下西门庆
2楼-- · 2019-08-27 12:26

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;
查看更多
家丑人穷心不美
3楼-- · 2019-08-27 12:36

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

查看更多
登录 后发表回答