Initial commit
This commit is contained in:
commit
45bfa311a1
15
LICENSE
Normal file
15
LICENSE
Normal file
@ -0,0 +1,15 @@
|
||||
Copyright (C) 2014 Jack-Benny Persson <jack-benny@cyberinfo.se>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
26
README.md
Normal file
26
README.md
Normal file
@ -0,0 +1,26 @@
|
||||
# Interest On Interest #
|
||||
This is a simple function I've made with PHP to calculate interest on interest.
|
||||
It's nothing fancy at all, but maybe it will be useful to someone. I've made it
|
||||
while learning PHP.
|
||||
|
||||
## Usage ##
|
||||
First argument to the script is the amount of money on your savings account, the
|
||||
second argument is the interest (without the percent sign) and the third
|
||||
(optional) argument is the number of years. For example if you have 50.000 in
|
||||
your savings account, and the interest is 3% and you want to know how much
|
||||
money you will have after 8 years:
|
||||
|
||||
php interest.php 50000 3 8
|
||||
|
||||
Or if you've made the script executable you can run it as follow:
|
||||
|
||||
./interest 50000 3 8
|
||||
|
||||
If you leave out the number of years the script will calulate the savings after
|
||||
one year.
|
||||
|
||||
## Copying ##
|
||||
Copyright 2014 Jack-Benny Persson (jack-benny@cyberinfo.se)
|
||||
|
||||
This program is release under GNU GPL version 2, please see the LICENSE file
|
||||
more information.
|
50
interest.php
Executable file
50
interest.php
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
/* A simple function to calculate 'interest on interest' together with
|
||||
a simple usage of the function.
|
||||
Copyright 2014 - Jack-Benny Persson <jack-benny@cyberinfo.se>
|
||||
Released under GNU GPL v.2 */
|
||||
|
||||
function InteOnInte($amount, $interest, $year=1)
|
||||
{
|
||||
$totalAmount = pow($interest / 100 + 1, $year) * $amount;
|
||||
return $totalAmount;
|
||||
}
|
||||
|
||||
function Usage()
|
||||
{
|
||||
print "Usage: php interest.php {amount to start with} {interest} [years]\n";
|
||||
print "Example: php interest.php 50000 3 10\n\n";
|
||||
print "Copyright 2014 - Jack-Benny Persson <jack-benny@cyberinfo.se>\n";
|
||||
}
|
||||
|
||||
// Sanity check
|
||||
if (!isset($argv[1]) || !isset($argv[2]))
|
||||
{
|
||||
print "Please enter amount and interest!\n";
|
||||
Usage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Declare some variables
|
||||
$money = $argv[1];
|
||||
$inter = $argv[2];
|
||||
|
||||
// If the user entered years
|
||||
if (isset($argv[3]))
|
||||
{
|
||||
$years = $argv[3];
|
||||
$mySavings = InteOnInte($money, $inter, $years);
|
||||
printf ("After %d years with %.2f%% interest on %.2f you will have %.2f\n",
|
||||
$years, $inter, $money, $mySavings);
|
||||
}
|
||||
|
||||
// If the user did not enter years
|
||||
else
|
||||
{
|
||||
$mySavings = InteOnInte($money, $inter);
|
||||
printf ("After 1 year with %.2f%% interest on %.2f you will have %.2f\n",
|
||||
$inter, $money, $mySavings);
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user