I'm a green green newbie trying to write a simple program in PHP. I use an HTML form to ask a "diner" to select an entree, which sends the choice to a PHP program.The PHP program is supposed to echo the entree choice, suggest a drink to the diner, and then tell the diner what the cost of the entree, drink is--including tax and tip.
The first function select_beverage accepts the choice of entree and echoes out the suggested drink and drink price. It then calls function wallet_buster which calculates the taxed cost of the bill. Wallet_buster()
is then supposed to return the taxed cost back to select_beverage()
which in turn should return the taxed cost back to the variable that called select_beverage.
I can get a simplified version of this program to work but not this beast. My teacher suggested that I save the value returned from wallet_buster as a variable, which I would then return at the end of the if/else
cascade. I've tried to follow that suggestion in this code but it's not working. I've also tried
return wallet_buster($steak_price, $steak_drink_price);
in each if/else
function but that's not working either.
Thanks in advance for any enlightenment you can provide!
<?php
echo "<h3>Thank you for dining at Elysium Excelsior</h3><br>";
function wallet_buster($entree_price, $drink_price) {
$taxed_cost = 1.1 * ($entree_price + $drink_price);
echo "<br/>";
return $taxed_cost;
}
function select_beverage($dinner) {
$steak_price = 27.50;
$steak_drink = "Justin Cabernet Sauvignon";
$steak_drink_price = 13.15;
$salmon_price = 24.95;
$salmon_drink = "Russian River Pinot Noir";
$salmon_drink_price = 12.25;
$barbecue_pork_price = 22.99;
$barbecue_pork_drink = "Dogfish Head 120 Minute IPA";
$barbecue_pork_drink_price = 7.99;
$chicken_price = 21.50;
$chicken_drink = "Blue Nun Sauvignon Blanc";
$chicken_drink_price = 12.25;
if ($dinner == "1") {
echo "The filet mignon pairs wonderfully with a glass of " . $steak_drink .
at a price of $" . $steak_drink_price . ".<br/>";
echo "<br/>";
$receipt = wallet_buster($steak_price, $steak_drink_price);
}
else if ($dinner == "2") {
echo "A glass of " . $salmon_drink . " for a luxuriously priced $" .
$salmon_drink_price . " is a wonderful complement to our
salmon."".<br/>";
echo "<br/>";
$receipt = wallet_buster($steak_price, $steak_drink_price);
}
else if ($dinner == "3") {
echo "Try a pint of " . $barbecue_pork_drink . " for only $" .
$barbecue_pork_drink_price . "."".<br/>";
echo "<br/>";
$receipt = wallet_buster($steak_price, $steak_drink_price);
}
else if ($dinner == "4") {
echo "Stiller and Meara invite you to try " . $chicken_drink . " at $" .
$chicken_drink_price . " per glass with the chicken!"".<br/>";
echo "<br/>";
$receipt = wallet_buster($steak_price, $steak_drink_price);
}
else {
echo "Please select an entree from our drop-down menu and we will recommend
a beverage suited to your choice.";
echo "<br/>";
}
return $receipt;
}
$dinner = $_GET["entree"];
$big_deal_meal = select_beverage($dinner);
echo "<br>";
echo "We encourage our patrons to tip well; given your menu selections, we ` `believe your bill should be : $" . (1.25 * $big_deal_meal);
?>