...

View Full Version : calculating discounted price and if statement



Lisawynn
04-27-2006, 06:25 PM
Hi. There is a problem with the following if statement and I can't figure out where I went wrong. It seems that $cost is being tested the first 2 times but if $cost is over $100, the value of $discount is a negative number. Can someone please take a look and tell me where my error is? Thanks very much!!



<? if ($cost < 50)
{
$discount=0;
}

else if ($cost >= 50 || $cost < 100)
{
$rate=100 - $cost;
$discount=$rate *.10;
}

else if ($cost >= 100 || $cost < 150)
{
$rate=150 - $cost;
$discount=$rate *.08;
}

else if ($cost >= 150 || $cost < 200)
{
$rate=200 - $cost;
$discount=$rate *.06;
}

else
{
print "I don't know what was selected";
}
print $discount;

?>

Thanks!!!

GJay
04-27-2006, 06:28 PM
It doesn't make much sense having || in your conditions, I think you meant to use &&

Lisawynn
04-27-2006, 06:44 PM
of COURSE that is what I meant........Thanks for pointing it out and of course, now it works great!!! Why was I using OR????? momentary insanity I think!!!!!

Thanks :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum