Hi all- first post, forgive me if this is in the wrong place, as it’s not exactly a “new topic”… I have a frustrating code issue in a school assignment. I can’t find a minor bug. From the Ch. 3 assignment which this one is based on:
The page provided by software-order.html should ask the user for the number of copies and the required operating system. These inputs will be submitted to software-order.php for processing. This program should calculate: the subtotal for the order (each copy sells for 35.00); a 7% tax (which is 0.07 times the subtotal); the shipping and handling charge, which is 1.25 for each copy; and the total cost (the subtotal plus the shipping/ handling charge plus the tax). The program should display the operating system, the number of copies ordered, the sub-total, the tax, the shipping/ handling, and the total cost. For example if the user inputs 5 copies, the subtotal will be 5 * 35.00 = 175.00, the tax will be 12.25, the shipping/ handling will be 6.25, and the total cost will be 193.50.
Here’s my php code:
$os = $_POST['os'];
$numCopies = $_POST['numCopies'];
$cost = 35.00;
$subtotal = $numCopies * $cost;
**$tax = $subtotal * 0.07**;
$shippingAndHandling = $numCopies * 1.25;
$totalCost = $subtotal + $tax = $shippingAndHandling;
print("<p>You ordered $numCopies copies of SaveTheWorld for $os at $$cost each.</p>");
print("<p>Subtotal: $$subtotal</p>");
print("<p>Tax: $$tax</p>");
print("<p>Shipping and Handling: $$shippingAndHandling</p>");
print("<p>Total: $$totalCost</p>");
But, my output result is:
Your Order
You ordered 5 copies of SaveTheWorld for Linux at $35 each.
Subtotal: $175
Tax: $6.25 <–???
Shipping and Handling: $6.25
Total: $181.25 <–???
The tax, and therefore the total, is coming out wrong. The directions say “7% tax (which is 0.07 times the subtotal)” and “the subtotal will be 5 * 35.00 = 175.00, the tax will be 12.25” (which checks out by calculator), and my code says:
$numCopies = $_POST['numCopies'];
$cost = 35.00;
$subtotal = $numCopies * $cost;
$tax = $subtotal * 0.07;
I can’t figure out how my tax is coming out at 6.25 instead of 12.25, nor why the total is off by only a $6 difference. I googled how to solve for X on a scientific calculator (not the Windows 10 calc, that thing is no help), and for 175*x=12.25, I got x=0.07. Please help!
Thanks, -Tim