Question: Change the code that determines the discount percent - 3. Change the if statement so customers of type R with a subtotal thats greater than
Change the code that determines the discount percent -
3. Change the if statement so customers of type R with a subtotal thats greater than or equal to $250 but less than $500 get a 25% discount and those with a subtotal of $500 or more get a 30% discount. Next, change the if statement so customers of type C always get a 20% discount. Then, test these changes.
4. Add another type to the if statement so customers of type T get a 40% discount for subtotals of less than $500, and a 50% discount for subtotals of $500 or more. Also, make sure that customer types that arent R, C, or T get a 10% discount. Then, test these changes.
5. Test the application again, but use lowercase letters for the customer types. Note that these letters arent evaluated as capital letters.
6. Modify the code so the users can enter either capital or lowercase letters for the customer types. To do that, use logical operators. Then, test this change.
Use a switch statement with nested if statements to get the same results -
7. Code a switch statement right before the if statement. This statement should provide the structure for handling the three cases for customer types: R, C, and T. Then, within each of these cases, you can copy the related code from the if statement below to provide for the discounts that are based on subtotal variations. In other words, you can nest the if statements within the switch cases.
8. Comment out the entire if statement thats above the switch statement. Then, test to make sure the switch statement works correctly.
9. If you havent done so already, modify the switch statement so it works for both lowercase and uppercase entries of the three customer types. To do that, use the strtoupper function to convert the customer type to uppercase before its evaluated. Then, test that change.
index.php -
$customer_type = filter_input(INPUT_POST, 'type'); $invoice_subtotal = filter_input(INPUT_POST, 'subtotal');
if ($customer_type == 'R') { if ($invoice_subtotal < 100) { $discount_percent = .0; } else if ($invoice_subtotal >= 100 && $invoice_subtotal < 250) { $discount_percent = .1; } else if ($invoice_subtotal >= 250) { $discount_percent = .25; } } else if ($customer_type == 'C') { if ($invoice_subtotal < 250) { $discount_percent = .2; } else { $discount_percent = .3; } } else { $discount_percent = .0; }
$discount_amount = $invoice_subtotal * $discount_percent; $invoice_total = $invoice_subtotal - $discount_amount;
$percent = number_format(($discount_percent * 100)); $discount = number_format($discount_amount, 2); $total = number_format($invoice_total, 2);
include 'invoice_total.php';
?>
invoice_total.php -
Invoice Total Calculator
Enter the values below and click "Calculate".
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
