Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is the syntax right?

Status
Not open for further replies.

dodgyone

Technical User
Jan 26, 2001
431
GB
I'm doing this exercise from a book but the calulation does not seem to be working.

I put the $Quantity and $Discount vlaes after the url (i.e. ?Quantity=10&Discount=5) but I keep on gettinga minus even though I use abs to get an absolute figure....

<?php
/* $Quantity has to passed to this web page from either a form, in the URL or on this page */

$Cost = 2000.00;
$Tax = 0.06;
$Quantity = abs($Quantity);
$Discount = abs($Discount);
$Tax++; // $Tax is now worth 1.06
$TotalCost = (($Cost * Quantity) - $Discount) * $Tax;
$Payments = round ($TotalCost, 2) / 12;
// Now print the results
print (&quot;You requested to purchase $Quantity widget(s) at \$$Cost each.\n<P>&quot;);
print (&quot;The total with tax, minus your \$$Discount, comes to $&quot;);
printf (&quot;%01.2f&quot;, $TotalCost);
print (&quot;.\n<P>You may purchase the widget(s) in 12 monthly installments of $&quot;);
printf (&quot;%01.2f&quot;, $Payments);
print (&quot; each.\n<P>&quot;);

?>

thanks for any help or suggestions given...
 
In your $TotalCost =(($Cost * Quantity) - $Discount) * $Tax
statement, you're missing the '$' in front of Quantity
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top