/
PHPLesson5Obj1v3.php
74 lines (55 loc) · 2.26 KB
/
PHPLesson5Obj1v3.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<font style="font-size:16px;">
Thank you for dining at the <i>Homesick Restaurant</i>!
<br/>
<br/>
<?
/*Here's where we pull the information from the form into the PHP.*/
$dinner = $_GET["entree_choice"];
//function to pair the entree choice and beverage together
function select_beverage($dinner) {
if ($dinner == "Steak") {
$beverage = "Fruit Punch";
}
else if ($dinner == "Salmon") {
$beverage = "Ginger Ale";
}
else if ($dinner == "Barbecue Pork") {
$beverage = "Sparkling Cider";
}
else if ($dinner == "Chicken") {
$beverage = "Diet Coke";
}
else {
echo "ERROR: Please return to our menu and make a selection.";
}
return $beverage;
}
//defines the $beverage value so it can be used in the tally
$beverage = select_beverage($dinner);
//this is where we display the data from the form and the function along with static HTML text
$appetizer = "House Salad";
$drink = $beverage;
$entree = $dinner;
$dessert = "Apple Pie";
$appetizer_price = 5.95;
$drink_price = 8.95;
$entree_price = 9.75;
$dessert_price = 4.75;
$subtotal = $appetizer_price + $drink_price + $entree_price + $dessert_price;//cost of menu items in order
$tax = $subtotal *.08;//cost with tax
$tip = $subtotal * .15;//cost including tip
$grand_total = $subtotal + $tax + $tip;
?>
<table>
<tr><td><strong>Your Menu Choice</strong></td><td><strong>Item Price</strong></td></tr>
<tr><td><? echo $appetizer; ?></td><td><? echo number_format($appetizer_price,2); ?></td></tr>
<tr><td><? echo $drink; ?></td><td><? echo number_format($drink_price,2); ?></td></tr>
<tr><td><? echo $entree; ?></td><td><? echo number_format($entree_price,2); ?></td></tr>
<tr><td><? echo $dessert; ?></td><td><? echo number_format($dessert_price,2); ?></td></tr>
<tr><td><strong>Subtotal</strong></td><td><? echo number_format($subtotal,2); ?></td></tr>
<tr><td><strong>Tax</strong></td><td><? echo number_format($tax,2); ?></td></tr>
<tr><td><strong>Tip</strong></td><td><? echo number_format($tip,2); ?></td></tr>
<tr><td><strong>Grand Total</strong></td><td><? echo number_format($grand_total,2); ?></td></tr>
</table>
<br/>
Please come see us again!