From 45bfa311a14fef3b41aa83291906cf7a326c2d02 Mon Sep 17 00:00:00 2001 From: Jack-Benny Persson Date: Sun, 15 Jun 2014 14:28:20 +0200 Subject: [PATCH] Initial commit --- LICENSE | 15 +++++++++++++++ README.md | 26 ++++++++++++++++++++++++++ interest.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100755 interest.php diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3717fbb --- /dev/null +++ b/LICENSE @@ -0,0 +1,15 @@ +Copyright (C) 2014 Jack-Benny Persson + +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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..50facb9 --- /dev/null +++ b/README.md @@ -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. diff --git a/interest.php b/interest.php new file mode 100755 index 0000000..9e3b0e9 --- /dev/null +++ b/interest.php @@ -0,0 +1,50 @@ +#!/usr/bin/php + + 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 \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); +} + +?>