Thread: If statement help...

  1. #1
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114

    If statement help...

    I need some help, with 'if statements'. I can't seem to find the right way to explain it...
    Like making my application do something if the input is between 2 numbers.
    Code:
    if (lvl > 31)(lvl < 71)
    {......
    ......}
    Sorry I couldnt explain very well... Thanks to anyone that can help.

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    You are just leaving out the "and" operation.

    Think about your problem in plain English first:

    "I want to do something if lvl is greater than 31 and lvl is less than 71."

    Turning that into C++:

    Code:
    if ( (lvl > 31) && (lvl < 71) )
    {
    ....code....
    }
    Notice the only real difference is the "&&".

    In C++ "&&" means "and". You can use it in "if" statement to do these kind of things.
    My Website

    "Circular logic is good because it is."

  3. #3
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204
    I think you're looking for:

    Code:
    if (lvl > 31 && lvl < 71)
    {......
    ......}
    The "&&" means AND. So if they are both TRUE, the if statement is executed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. Meaning of this statement?
    By @nthony in forum C Programming
    Replies: 7
    Last Post: 07-16-2006, 02:57 AM
  3. if/break statement
    By Apropos in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2005, 02:33 PM
  4. string & if statement
    By Curacao in forum C++ Programming
    Replies: 4
    Last Post: 05-02-2003, 09:56 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM