Results 1 to 8 of 8

Thread: if help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432

    Lightbulb if help

    ok im getting errors when i try this saying that (Boolean,int) are not allowed??? first if works fine all the else ifs are %^&*ed up ?

    if (intSetPieces > 0 || intSetPieces <= 199)
    {
    dblPay = .50D;
    }
    else if (intSetPieces = 200 || intSetPieces <= 399)
    {
    dblPay = .55D;
    }
    else if (intSetPieces = 400 || intSetPieces <= 599)
    {
    dblPay = .60D;
    }
    else if (intSetPieces = 600 || intSetPieces <= 100)
    {
    dblPay = .65D;
    }
    else
    {
    intError = 1;
    strError = "Error With Calculating Payment";
    }

  2. #2
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    You need double equal signs to compare. Otherwise you're asigning a value to a variable

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Posted by marnitzg
    You need double equal signs to compare. Otherwise you're asigning a value to a variable
    I think that is what he wants to do. I couldnt see using the equals operator by itself. I wouldn't be a statement.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    In the if statements, not in the blocks:

    Code:
     else if (intSetPieces = 200 /* wrong */ || intSetPieces <= 399)
    {
    dblPay = .55D; // ok
    }
    Oh, btw you should use logical and (&&) not or (||) in the first if, else it catches everything (every number is greater 0 or less than 199).
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Oh yeah. right. I just took a quick look at the the first conditional statement sorry. Yeah 308holes CornedBee is right. Using the short circut operator || if the first condition equates to true the second condition will just be skiped so intSetPieces could end up being more than 199 clearly not what you want.

  6. #6
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    Originally posted by Dilenger4
    I think that is what he wants to do. I couldnt see using the equals operator by itself. I wouldn't be a statement.
    Confused

  7. #7
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Sorry marnitzg. I didnt see the assignment operator in the second conditional statement so i thought you were refering to the line dblPay = .50D; meaning it should be dblPay == .50D;

  8. #8
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372

Posting Permissions

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



Click Here to Expand Forum to Full Width