Question : Php: need help

Hello. Once again having problems with hometask. My home task is the following:

Print  out a receipt for a restaurant meal (must contain the following)
1.      String variables for each course: Pasta Di Pina, pepsi, cake, entrĂ©e. Each course variable should contain the customer's menu choice (ie. "hotdog").
2.      float or integer variable  in dollars for each course price.
3.      A float variable for the 8% sales tax, and another one for the customer's 15% tip amount.
Make everything with echo statements and  list out the meal items and prices, the subtotal, tax, tip, and grand total.

I have created this code:

<h3>Restaurant meal  and prices</h3>

<?



$PastaDPina = 13;
$pepsi = 8;
$cake =4;
$entree = 11.2;

echo "PastaDPina: ". $PastaDPina."$<br>";
echo "Pepsi Cola: ".$pepsi."$<br>";
echo "Cake: ".$cake."$<br>";
echo "Entree: ".$entree."$<br>";

$total=$PastaDPina+$pepsi+$cake+$entree;
echo "<hr>";
echo "Total price is: <b>".$total."</b>";

?>


So i have listed out the meal items and prices and total. I do not know exactly how to list out subtotal, tax, tip, and grand total. Also how can i create A float variable for the 8% sales tax, and another one for the customer's 15% tip amount.? This is my third lesson on php

Answer : Php: need help

Hi,

Please have a look at the following code.

If you are using double quotes for your strings you do not need to do ".variable." around the variables.

Hope this helps,

John
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:
<html>
<head>
<title>Menu</title>
</head>
<body>
<h3>Restaurant meal  and prices</h3>
<?php
$PastaDPina = 13;
$pepsi = 8;
$cake = 4;
$entree = 11.2;
$tax = 0.08;
$tip = 0.15;

echo "PastaDPina: $PastaDPina$<br>";
echo "Pepsi Cola: $pepsi$<br>";
echo "Cake: $cake$<br>";
echo "Entree: $entree$<br>";

$total=$PastaDPina+$pepsi+$cake+$entree;
echo "<hr>";
echo "Sub-total: <b>".number_format($total,2)."</b><br>";
$salestax = number_format($total*$tax,2);
echo "Sales Tax: <b>".$salestax."</b><br>";
$custtip = ($total+$salestax)*$tip;
echo "Sales Tax: <b>".number_format($custtip,2)."</b><br>";
echo "Grand Total: <b>".number_format($total+$salestax+$custtip,2)."</b><br>";
?>
</body>
</html>
Random Solutions  
 
programming4us programming4us