Martha's CIS 52 Lab #2 Number Exercise #5

Lab #2 Exercise #5. 5.  Create a PHP script which takes two parameters: (1) the number of years and (2) the amount of money to be put on a savings account.  Include a function that   calculates the amount that will have been reached after a given number of years. Print the amount with no more than two decimals.  Come up with your own interest rate.

**************************************************************

CODES:

<?php
if (!isset($_POST['submit'])) {
?>
<form action="<?php $_SERVER['PHP_SELF']?>" method="post">
<input name="intRate" type="text" value="" /> Expected Interest Rate (use whole numbers) <br />
<input name="investment" type="text" value="" /> Amount Invested (in 1000's) <br />
<input name="years" type="text" value="" /> Number of Years Invested <br />
<input name="submit" type="submit" value="Submit" />
</form>
<?php
} else {

function calculateSavings($years, $investment) {
// Declare variables
$years = $_POST['years'];
$interestRate = ($_POST['intRate']);
$investment = $_POST['investment'];
// Create calculations
$savings = (($interestRate)/100)* $investment;
$totalSavings = $years * $savings;
$totalAmount = $totalSavings + $investment;
echo "Your expected savings rate was ".$interestRate."% and the amount of money you invested was \$".$investment.".<br />";
echo "In ".$years." years you will have earned \$".round($totalSavings, 2).", and your total investment will become $".$totalAmount.".</p>";
}
calculateSavings($years, $investment);
}
?>

 

**************************************************************

ANSWER:

Expected Interest Rate (use whole numbers)
Amount Invested (in 1000's)
Number of Years Invested