Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PHP QUESTION A company is selling widgets at $49.23 each. There is delivery char

ID: 3734712 • Letter: P

Question

PHP

QUESTION

A company is selling widgets at $49.23 each. There is delivery charge of 10% per widget and $10.00 per entire order. There is also 6% state sales tax. The 'no_widgets' entry of the PHP superglobal array $_POST stores the number of widgets ordered. Write the PHP statements that assigns the no of widgets from the $_POST array to a PHP variable and then calculates and displays the number of widgets ordered, the cost of the purchase, the cost of the delivery charge, the cost of the state sales tax, and the total cost of the order. For example, if the number of widgets is 2, then you code should display:

cost of 2 widget(s) is $98.46
delivery charge is $19.85 and state sales tax is $5.91
total cost is $124.21

The sales tax should apply only to the widgets themselves, and not to the delivery charge. All displayed amounts should be rounded to the nearest cent.

Explanation / Answer

<?php

if(!empty($_POST['no_widgets'])){ //Here checking the no .of widgets are null

$No_Widets = $_POST['no_widgets']; //Here storing the the no_widgets into a variable

$Total_Cost_Of_No_Widgets_Dollars = (49.23 * $No_Widets); //Calculating total cost

$Cost_Of_Delivery_Charge = ($Total_Cost_Of_No_Widgets_Dollars/100) * 10; //Caculating the delivery charge

$Cost_Of_Sales_Tax = ($Total_Cost_Of_No_Widgets_Dollars/100) * 6; //Caculating the sales tax

$Final_Cost_In_Dollars = $Total_Cost_Of_No_Widgets_Dollars + $Cost_Of_Delivery_Charge + $Cost_Of_Sales_Tax;

$Final_Cost_In_Cents = $Final_Cost_In_Dollars * 100; //Converting dollar to cent (1 dollar = 100 cents);

$Final_Cost_DeliveryCharge_In_Cents = $Cost_Of_Delivery_Charge * 100;

$Final_Cost_SalesTax_In_Cents = $Cost_Of_Sales_Tax * 100;

echo 'Total_Cost'.' '.$Final_Cost_In_Cents;

echo 'DeliveryCharge'.' '.$Final_Cost_DeliveryCharge_In_Cents;

echo 'SalesTax'.' '.$Final_Cost_SalesTax_In_Cents;

}

else{

echo 'No.of widgets are Null.........';

}

?>

Note : Remove the comments and excute the code...if any issues please comment me in the comment box...