Thread: range of values in an if statement

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    13

    range of values in an if statement

    In my if statement I want the values to be in a range say 70 - 80 for the condition to be true. I cannot seem to get it to work and am not sure if it is possible, any comment on how can I go about this.

    Thanks in advance

  2. #2
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    Code:
    if(x>70 && x<80)
    {
    }
    Is this what you want?

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    That means, x MUST be greater than 70 AND less than 80.

    As you know, && = boolean and

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    abh!shek gave code for the exclusive set. Here's the code for the inclusive set:
    Code:
    if(x>=70 && x<=80)
    {
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. disposing error
    By dropper166 in forum C# Programming
    Replies: 2
    Last Post: 03-30-2009, 11:53 PM
  2. performing range checks on variable values
    By broli86 in forum C Programming
    Replies: 12
    Last Post: 07-02-2008, 11:21 AM
  3. Overflow and range checking for mul/div
    By Elysia in forum C++ Programming
    Replies: 28
    Last Post: 06-06-2008, 02:09 PM
  4. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  5. Checking Multiple Values in if() statement
    By Zero_X in forum C++ Programming
    Replies: 6
    Last Post: 10-02-2006, 11:27 PM