我有这个脚本...
//initial value
$fund = 10;
$rebate = 0.01; // constant 1 percent
$maturity = 30; //days
echo '<ul>';
echo '<li>Day1 fund: $' . $fund . '</li>';
//day1 value
$fund = incfund($fund); //should return $10.10
echo '<li>Day2 fund: $' . $fund . '</li>';
//day2 value
$fund = incfund($fund); //should return $10.20
echo '<li>Day3 fund: $' . $fund . '</li>';
//day3 value
$fund = incfund($fund); //should return $10.30
echo '<li>Day4 fund: $' . $fund . '</li>';
echo '</ul>';
//continue increasing the fund value daily until day 30...
//function to increase $fund
function incfund($x){
for($i = 0; $i<=$maturity; $i++){
$newfund = $x + $rebate;
$fund = $newfund;
return $fund;
}
}
目前如果我运行脚本,它将输出:
Day1 fund: $10
Day2 fund: $10
Day3 fund: $10
Day4 fund: $10
当我真正想输出的是:
Day1 fund: $10.10
Day2 fund: $10.20
Day3 fund: $10.30
Day4 fund: $10.40
...
...
Day30 fund: $13.00
基本上,我要做的是计算 1% 的回扣并将其复利到原始基金,然后继续复利直到到期日。
为什么我不能做我想做的事可能是什么问题?