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

Using HTML and PHP Sales Amount| Overview: This program will calculate the amoun

ID: 3723389 • Letter: U

Question

Using HTML and PHP

Sales Amount| Overview: This program will calculate the amount of a discount based on a purchase amount and a customer code. This program is a one-file program, with no CSS needed Customer Code Calculatel Allow the user to enter in a sales amount, and select a customer code. The discount is calculated as: . C type customers get a 10 percent discount if they spend more than $100 . R type customers get a 20 percent discount if they spend more than $200, or a 10 percent discount if they spend $200 or less Print out the base sale, the discount, and the total (which is the sale, minus the discount). Format all output to 2 decimal places. Print an error if amount is not a number, if amount is less than 0, or if there was no code selected Examples: Exam 2 Sales Amount: 50 Custoe Code Exam 2 Sales Amount Exam R Customer Code: Error in inputs alculate

Explanation / Answer

<!-- Code in HTML and PHP-->

<!DOCTYPE html>

<html>

<body>

<form action=" " method="POST">

Salse Amount:

<input type="text" name="amount">

<br>

Customer Code:<br>

<input type="radio" name="code" value="R" checked>R<br>

<input type="radio" name="code" value="C">C<br>

<br>

<input type="submit" value="Calculate" name="Calculate">

</form>

<?php

if(isset($_POST["Calculate"]))

{

$amount=(double)$_POST['amount'];

$code=$_POST['code'];

if(preg_match("/^-?[1-9][0-9]*$/D",$amount)) // check a text numaric or not

{

if($code=='R')

{

if($amount>200)

{

$base=$amount ;   

$disc=0.20* $amount;

$total= $amount-$disc;

echo "base=".number_format((float)$base, 2, '.', '')."<br>";

echo "disc=".number_format((float)$disc, 2, '.', '')."<br>";

echo "total=".number_format((float)$total, 2, '.', '')."<br>";

}

elseif($amount>=0)

{

$base=$amount;

$disc=0.10 * $amount;

$total=$amount-$disc;

echo "base=".number_format((float)$base, 2, '.', '')."<br>";

echo "disc=".number_format((float)$disc, 2, '.', '')."<br>";

echo "total=".number_format((float)$total, 2, '.', '');

}

else

{

echo "Error in input";

}

}

else

{

if($amount>100)

{

$base=$amount;

$disc=0.10 *$amount;

$total=$amount-$disc;

echo "base=".number_format((float)$base, 2, '.', '')."<br>";

echo "disc=".number_format((float)$disc, 2, '.', '')."<br>";

echo "toatal=".number_format((float)$total, 2, '.', '');

}

elseif($amount>=0)

{

$base=$amount;

$disc=0;

$total=$amount;

echo "base=".number_format((float)$base, 2, '.', '')."<br>";

echo "disc=".number_format((float)$disc, 2, '.', '')."<br>";

echo "toatal=".number_format((float)$total, 2, '.', '');

}

else

echo "Error in input";

}

}

else

echo "Error in input";   

  

}

?>

</body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote