<html>
<body bgcolor=lightyellow>

<H1 Align=center>Custom Functions</h1>

<?php

error_reporting(E_ALL ^ E_WARNING);

echo "Our first call to a function";
echo "<br><br>";

printGreeting( );                       //call printGreeting function


echo "<hr><br>";        

echo "Our second function - Odd or Even? ";
echo "<br><br>";

odd_even(1,100);                        //call function and pass 2 arguments


echo "<hr><br>";        

echo "Our third function - future value ";
echo "<br><br>";

$amount = rand(100,5000);                       //random from 100 to 5000
$int    = rand(200,800) / 100;                  //interest from 2.00 to 7.99
$years  = rand(1,10);                           //random from 1 to 10

$value  = future_value($amount, $int, $years);  //pass and receive data

$formatted = sprintf("$%8.2f", $value);         //formatted with 2 decimal points

echo "The future value of $$amount @ $int% interest for $years years ";
echo "is: $formatted";

echo "<hr><br>";        

//-------------------------------------------------------------------------------
function printGreeting( )               //define printGreeting function
{
    $now = time( );                     //get the current date and time

    if (date('H',$now)  < 12)           //are hours < 12
        print "Good Morning -- ";
    else
        print "Good Afternoon -- ";

    print "the date/time is now " . date('r',$now);
}               

//-------------------------------------------------------------------------------
function odd_even($min, $max)           //function that accepts 2 parameters
{
    $rand  = rand($min, $max);          //rand number from min to max

    $rem   = $rand % 2;                         //the remainder of 2
    $which = ($rem == 0) ? 'even' : 'odd';      //is it odd or even?

    print "The number $rand is $which";
}  

//-------------------------------------------------------------------------------
function future_value($amt, $int, $year)  //function that accepts 3 parameters
{

    $int1 = 1 + $int/100;                 //1 + the interest rate
    $fv   = $amt * pow($int1, $year);     //future value of an amount

    return ($fv);                         //return the future value
}  

//-------------------------------------------------------------------------------
?>

<?php include "../include.php"; ?>              <!-- hyperlink to see the code -->
</body>
</html>