I am currently computing the deposit which is 100 plus interest rate and adds 100 in every year within a loop. That goal has been achieved but I need help in outputting the total of the iterated results from this loop. Please example code below. Thank you!
<?php
$deposit = 100;
$rate = 5;
$rate = $rate / 100;
$year = 0;
while($year < 5){
$year++;
$deposit = $deposit + ($deposit * $rate);
echo "<strong>Year " .$year . ": </strong>" . number_format($deposit,2) ."<br>";
$total = $deposit = $deposit + 100;
$total = $total + $year;
}
echo "-------------------------" . "<br><strong> Total: " . number_format($total,2);
?>
I get this result from the loop which is a good thing. My goal is to add all these results from year1 to year5.
THIS THE OUTPUT OF THE LOOP:
Year 1: 105.00
Year 2: 215.25
Year 3: 331.01
Year 4: 452.56
Year 5: 580.19
Total: 0 ----- This is my goal