Jump to content

savings table


nickthrolson

Recommended Posts

Let us say we wanted to create a savings table. The columns represent the interest rates (6,7,8,9,10) percent. The rows represent the years (1,2,3, ... up to 12) If the savings in any given cell where = (1+interest)^(number of years) where in this case ^ is the power then print the table

 

I need help with this can anyone give me example how to start this off? for class is I'm in for college reading the book cant find any similar examples. Thanks!

Link to comment
https://forums.phpfreaks.com/topic/165454-savings-table/
Share on other sites

Is this what you want to create?

+----------+----------------+
|          | 6%             | ..
+----------+----------------+
| 1st year | base+intrest^1 | ..
+----------+----------------+
| 2nd year | base+intrest^2 | ..
+----------+----------------+
| 3th year | base+intrest^3 | ..
+----------+----------------+

 

Then this should do it:

<?php
$base = 100;
$years = range(1, 12);
$percents = range(6, 10);
$number_of_years = sizeof($years);
$total_percentages = sizeof($percents);
for ($i = 0; $i < $number_of_years; ++$i) {
    for ($j = 0; $j < $total_percentages; ++$j) {
        $base += ($base * ($percents[$j] / 100))^$years[$i];
        print 'Year: '. $years[$i] . ' Percentage: ' . $percents[$j] . ' Base+Intrest: ' . $base . '<br>';
    }
}
?>

 

It misses the markup to create the table though

Link to comment
https://forums.phpfreaks.com/topic/165454-savings-table/#findComment-872658
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.