Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2004
    Location
    Manitoba, CANADA
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    calculating discounted price and if statement

    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!!

    PHP Code:
    <?    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!!!

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    It doesn't make much sense having || in your conditions, I think you meant to use &&

  • #3
    New Coder
    Join Date
    Feb 2004
    Location
    Manitoba, CANADA
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •