Jump to content

reducing total cost by a percent


spillage

Recommended Posts

Hi im new to this and am reading an idiots guide to php but am stuck. i have a form with 3 items for sale. if item 1 has a  value of 100 then i want to discount this by 20%.  and leave the value of the others alone. i have used the if elseif to calculate different levels of discount but where would i actually remove the 20% value. i thought i could just $totalamount = $tireqty * TIREPRICE * $discount but it will not work. HOPE THIS MAKES SOME SENSE.

thanks.

 

if ($tireqty <=5)

$discount=0;

elseif ($tireqty >=5 && $tireqty <49)

$discount=0.95;

elseif ($tireqty >=50 && $tireqty<=99)

$discount=0.9;

elseif ($tireqty >100)

$discount=0.80;

 

 

$totalamount = 0.00;

 

define('TIREPRICE', 100 );

define('OILPRICE', 10);

define('SPARKPRICE', 4);

 

$totalamount = $tireqty * TIREPRICE

            + $oilqty * OILPRICE

            + $sparkqty * SPARKPRICE;

           

           

 

echo 'Subtotal: £'.number_format($totalamount,2).'<br />';

 

$taxrate = 0.175;  // local sales tax is 17.5%

$totalamount = $totalamount  * (1 + $taxrate);

echo 'Total including tax: £'.number_format($totalamount,2).'<br />';

Link to comment
https://forums.phpfreaks.com/topic/97003-reducing-total-cost-by-a-percent/
Share on other sites

Can you try this:

 

if ($tireqty <=5)
$discount=0;
elseif ($tireqty >=5 && $tireqty <49)
$discount=0.95;
elseif ($tireqty >=50 && $tireqty<=99)
$discount=0.9;
elseif ($tireqty >100)
$discount=0.80;


$totalamount = 0.00;

define('TIREPRICE', 100 );
define('OILPRICE', 10);
define('SPARKPRICE', 4);

$totalamount = ($tireqty * TIREPRICE * $discount)
             + ($oilqty * OILPRICE)
             + ($sparkqty * SPARKPRICE);
             
             

echo 'Subtotal: £'.number_format($totalamount,2).'
';

$taxrate = 0.175;  // local sales tax is 17.5%
$totalamount = $totalamount  * (1 + $taxrate);
echo 'Total including tax: £'.number_format($totalamount,2).'
';

 

What output does it give?

look 1st if

<?php
if ($tireqty <5) $discount=1;// 1 to 4 no discount, must be 1 not 0
elseif ($tireqty <50) $discount=0.95; // 5 to 49 discount 5%
elseif ($tireqty< 100) $discount=0.9; // 50 to 99 discount 10%
else $discount=0.80; // 100 and more discount 20%
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.