0

我正在构建一个 ios ipad 应用程序,我在代码中有以下公式来计算一次性金额:

    LumpSum = 0;
    for (int n = 1; n<= int_YEARSlasts; n=n+1)
    {
        float x = ((1 + (float_IR/100)) / (1 + (float_ERret/100)));
        int y = (n - 1);
        LumpSum = LumpSum + (NEEDincome * pow(x, y));
    }

这段代码效果很好,给了我想要的一次性金额。

我想要做的是从这个公式中为从 1 到“int_YEARSlasts”的 n 上的每个值获取每个值

我不确定如何做到这一点,任何人都可以指出我正确的方向。

谢谢

4

2 回答 2

0

我假设你想在每个索引处存储 LumpSum:

 LumpSum = 0;
NSMutableArray *mutArrLumpSumValues = [NSMutableArray array];
for (int n = 1; n<= int_YEARSlasts; n=n+1)
{
    float x = ((1 + (float_IR/100)) / (1 + (float_ERret/100)));
    int y = (n - 1);
    LumpSum = LumpSum + (NEEDincome * pow(x, y)); 
    [mutArrLumpSumValues addObject:LumpSum];
}
NSLog(@" mutArrLumpSumValues : %@",mutArrLumpSumValues);
于 2012-08-27T12:45:04.240 回答
0
NSMutableArray *getValueArray = [[NSMutableArray alloc] init];
LumpSum = 0;
    for (int n = 1; n<= int_YEARSlasts; n=n+1)
    {
        float x = ((1 + (float_IR/100)) / (1 + (float_ERret/100)));
        int y = (n - 1);
        LumpSum = LumpSum + (NEEDincome * pow(x, y));
        [getValueArray addObject:LumpSum];
    }
 NSLog(@"Get Value Array: %@",getValueArray);

I think it will be helpful to you.

于 2012-08-27T12:44:20.257 回答