range of values in an if statement

This is a discussion on range of values in an if statement within the C Programming forums, part of the General Programming Boards category; In my if statement I want the values to be in a range say 70 - 80 for the condition ...

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21