Lab #1 Exercise #10. Ask the user how many Euros he or she spent in Germany? Write a function to convert the Euros to U.S. dollars based on today's exchange rate.
10/17/09 - $100 = 67.08 Euros; 100 Euros = $149.08; $dollar = 67.08/100 * $euro; $euro = 149.09/100 * $dollar
**************************************************************
CODES:
<?php
function getMoney($euros) {
$euros = $_POST['euros'];
return $euros;
}
function converter($euros) {
getMoney($euros);
settype ($euros, float);
$dollars = ((149.08 * $euros)/100);
$dollars = round($dollars, 2);
return $dollars;
}
if (!isset($_POST['submit'])) {
?>
<p>Hello, Traveler! How many Euros did <?php echo strtoupper("you") ?> spend in Germany?<br />
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" />
<input type="text" size="12" maxlength="20" name="euros" />
<input type="submit" value="Convert Euros" name="submit" /></form></p>
<?php
} elseif (( $euros !== 0) || ($euros !== '')) {
echo "The exchange rate on 10/17/09: $100 is worth 67.08 Euros, and €100 is worth 149.08 dollars.<br />";
echo "The formula for converting Euros to dollars, therefore, is €1 = \$1.4908.<br /><br />";
echo "You spent €".getMoney($euros)." Euros in Germany, which is the equivalent of $".converter($_POST["euros"])." in American money. Hope you enjoyed your trip!!";
} else {
echo "Sorry, you did not complete the form properly.";
}
?>
**************************************************************
ANSWER:
Hello, Traveler! How many Euros did YOU spend in Germany?