Thread: C++ If Statements Help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,337
    Hey Mary Pat.
    Code:
    	if (number2 < number1 < number3)
    		middle = number1; if (number1 < number2 < number3) 
    			middle = number2; if (number1 < number3 < number2) 
    				middle = number3;
    You can't code like this - it's not valid syntax. How that reads is:

    if number2 is less than number1 is less than number 3 ...

    Stick with one condition inside the parens for now until you gain more experience.

    Try something like this:
    Code:
    int temp ; 
    if (low > middle) { 
      temp = low ;
      low = middle ; 
      middle = temp
    }
    And then do the same thing with low and high (or number"x" and number"y"). Then, do middle and high.

    Todd
    Last edited by Dino; 01-17-2008 at 03:07 PM. Reason: typo

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 10:42 AM
  3. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 11:36 AM
  4. Statements and Functions
    By GeekFreak in forum C++ Programming
    Replies: 5
    Last Post: 08-15-2002, 12:34 PM
  5. Switch statements for strings
    By cxs00u in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2002, 03:38 PM