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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.