Beginner if/switch question

This is a discussion on Beginner if/switch question within the C++ Programming forums, part of the General Programming Boards category; Hi, I've been wondering, what syntax would you use to check an if or switch statement against a range of ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    4

    Beginner if/switch question

    Hi, I've been wondering, what syntax would you use to check an if or switch statement against a range of values, instead of just one? For example, how would I check to see if an entered value is between, say, 5 and 25 instead of just checking each number individually? I'm still really new to everything and I've been curious of this for a while, but haven't been able to figure it out. Any help would be greatly appreciated!

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,243
    Quote Originally Posted by GuitarNinja View Post
    Hi, I've been wondering, what syntax would you use to check an if or switch statement against a range of values, instead of just one? For example, how would I check to see if an entered value is between, say, 5 and 25 instead of just checking each number individually? I'm still really new to everything and I've been curious of this for a while, but haven't been able to figure it out. Any help would be greatly appreciated!
    If a number is greater than or equal to 5, and less than or equal to 25, then it's between 5 and 25.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    Use the || and &&
    Code:
    if(value >= 5 && value <= 25){}
    Woop?

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    4
    Ok, that makes sense now, I think you answered it perfectly. Thanks guys!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner: Linked List question
    By WeatherMan in forum C++ Programming
    Replies: 2
    Last Post: 04-03-2008, 07:16 AM
  2. Quick IF statement question (beginner)
    By jim.rattlehead in forum C Programming
    Replies: 23
    Last Post: 11-29-2007, 05:51 AM
  3. beginner question
    By Barrot in forum C++ Programming
    Replies: 4
    Last Post: 08-19-2005, 02:17 PM
  4. Question About External Files (Beginner)
    By jamez05 in forum C Programming
    Replies: 0
    Last Post: 08-11-2005, 07:05 AM
  5. Beginner on Win32 apps, lame question.
    By Templario in forum C Programming
    Replies: 3
    Last Post: 11-06-2002, 07:39 PM

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