Stuck on my online course

I am stuck on line online course. Can someone please help me. I paste my html and php.

My instructor said this: Hi Ali,

You are using your function to pick the drink, inside the function, and using an outside value, the dinner, to determine the drink so you want to pull the outside value inside the function.

function_call($dinner); //You already know $dinner

if you use function_call($drink); //How can you determine the drink by inputting the drink? Make sense

I do not get what he is saying.

Here is my php:


    Meal Receipt <?

    function select_beverage() {

        if ($dinner == "5") {
      
     		$drink == "Pepsi";         
      
     }
    
    else if ($dinner == "6") {
    
     		$drink = "RC";   
    

    }

    else if ($dinner == “7”) {

     $drink = "Coke";
    

    }
    else if ($dinner == “8”) {

     $drink = "Zero";     
    

    }
    else

    {

     $drink = "None";
    

    }

    return $drink;
    }
    return select_beverage($drink);

    ?>

    <? $dinner = $_GET["entree"]; $appetizer = "Salad"; $dessert = "Ice Cream"; $appetizer_price = .99; $drink_price = .99; $ice_cream_price = 1.99; $sales_tax = 0.08; $t = 0.15; $drink_capture = select_beverage($drink); $tmc = $appetizer_price + $drink_price + $dinner + $ice_cream_price; //total meal cost without tax $tax = $tmc * $sales_tax; //multiplying with tax to show tax on receipt $tip = ($tmc + $tax) * $t; //total with tax times tip $total_bill = $tmc + $tax + $tip ?>
  • Entree: <? echo $dinner; ?>
  • <? echo $drink_capture." : ".$drink_price; ?>
  • <? echo $dessert." : ".$ice_cream_price; ?>
  • <? echo $appetizer." : ".$appetizer_price; ?>
  • Tax: <? echo $tax; ?>
  • Tip: <? echo $tip; ?>
  • Total: <? echo $total_bill; ?>

Here is my html for user input:

MEAL DEAL

Choice of Entrees:

Please choose... Barbecue Pork Steak Chicken Salmon

Hello, have a look at my code below:
the first one i have correct a few errors in yours to make it work as i expected.
[php]


    Meal Receipt <?php
    // function select_beverage()	// error here, passing a variable into the function below, but it can't accept it?
    function select_beverage($dinner)	// dinner. 
    {
    	if ($dinner == "5") 
    	{
    		//$drink == "Pepsi"; // error here too many equal signs!
    		$drink = "Pepsi"; 	 // corrected
    	}
    	elseif($dinner == "6") 
    	{
    		$drink = "RC";
    	}
    	elseif($dinner == "7") 
    	{
    		$drink = "Coke";
    	}
    	elseif($dinner == "8") 
    	{
    		$drink = "Zero";
    	}
    	else
    	{
    		$drink = "None";
    	}
    	return $drink;
    }
    //return select_beverage($drink); // this line doesn't need to be here because you call it below?? see **
    
    $dinner = $_GET["entree"];
    $appetizer = "Salad";
    $dessert = "Ice Cream";
    $appetizer_price = .99;
    $drink_price = .99;
    $ice_cream_price = 1.99;
    $sales_tax = 0.08;
    $t = 0.15;
    /* 
    ** we will use this function call as it is setting a variable.
    */
    $drink_capture = select_beverage($dinner); // Corrected: $dinner not $drink
    
    $tmc = $appetizer_price + $drink_price + $dinner + $ice_cream_price; 
    $tax = $tmc * $sales_tax; 
    $tip = ($tmc + $tax) * $t; 
    $total_bill = $tmc + $tax + $tip
    ?>
     
    <br/>
    <ul>
    	<li> Entree: <?php echo $dinner; ?> </li>
    	<li> <?php echo $drink_capture." : ".$drink_price; ?> </li>
    	<li> <?php echo $dessert." : ".$ice_cream_price; ?> </li>
    	<li> <?php echo $appetizer." : ".$appetizer_price; ?> </li>
    	<li> Tax: <?php echo $tax; ?> </li>
    	<li> Tip: <?php echo $tip; ?> </li>
    	<li> Total: <?php echo $total_bill; ?> </li>
    </ul>
    
[/php]

outputs:
[php]
Meal Receipt

* Entree: 5
* Pepsi : 0.99
* Ice Cream : 1.99
* Salad : 0.99
* Tax: 0.7176
* Tip: 1.45314
* Total: 11.14074

[/php]

Now my function is similar to yours:
[php]


    Meal Receipt <?php function select_bev($drink) // dinner. { if ($drink == "Pepsi") { $xdinner = 5; } elseif($drink == "RC") { $xdinner = 6; } elseif($drink == "Coke") { $xdinner = 7; } elseif($drink == "Zero") { $xdinner = 8; } else { $xdinner = "None"; } return $xdinner; }
    $drink  = $_GET["drinks"]; // drinks
    $xappetizer = "Salad";
    $xdessert = "Ice Cream";
    $xappetizer_price = .99;
    $xdrink_price = .99;
    $xice_cream_price = 1.99;
    $xsales_tax = 0.08;
    $xt = 0.15;
    
    $xdinner = select_bev($drink); // drink
    $xtmc = $xappetizer_price + $xdrink_price + $xdinner + $xice_cream_price; //total meal cost without tax
    $xtax = $xtmc * $xsales_tax; //multiplying with tax to show tax on receipt
    $xtip = ($xtmc + $xtax) * $xt; //total with tax times tip
    $xtotal_bill = $xtmc + $xtax + $xtip
    ?>
     
    <br/>
    <ul>
    	<li> Entree: <?php echo $xdinner; ?> </li>
    	<li> <?php echo $drink." : ".$xdrink_price; ?> </li>
    	<li> <?php echo $xdessert." : ".$xice_cream_price; ?> </li>
    	<li> <?php echo $xappetizer." : ".$xappetizer_price; ?> </li>
    	<li> Tax: <?php echo $xtax; ?> </li>
    	<li> Tip: <?php echo $xtip; ?> </li>
    	<li> Total: <?php echo $xtotal_bill; ?> </li>
    </ul>
    
[/php]

outputs:

[php]
Meal Receipt

* Entree: 7
* Coke : 0.99
* Ice Cream : 1.99
* Salad : 0.99
* Tax: 0.8776
* Tip: 1.77714
* Total: 13.62474

[/php]

and the HTML form
[php]

MEAL DEAL

Choice of Entrees:

Please choose... Barbecue Pork Steak Chicken Salmon

Choice of Drinks:

Please choose... Pepsi RC Coke Zero [/php]

not sure if this was what you are looking for but i hope it helps.

by the way, i notice you use short open tags <? you should use the full <?php on all your scripts to ensure they work on servers with short open tags turned off (quite common!)

:wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service