6 Replies - 278 Views - Last Post: 16 March 2011 - 03:34 AM Rate Topic: -----

#1 lokyblue  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 23-March 10

if statement

Posted 15 March 2011 - 03:37 PM

i cant use this code like this

if!(num2 > num4){



temp=num2;

num2=num4;

num4=temp;

}




should i just use < or is there a syntax to wright this code properly?
Is This A Good Question/Topic? 0
  • +

Replies To: if statement

#2 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1875
  • View blog
  • Posts: 20,282
  • Joined: 17-March 01

Re: if statement

Posted 15 March 2011 - 03:39 PM

So you're trying to do "if not greater than" ?
Was This Post Helpful? 0
  • +
  • -

#3 lokyblue  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 23-March 10

Re: if statement

Posted 15 March 2011 - 03:42 PM

exactly i can use just if (num2 < num4 ) but is there a way to wright as if!(num2 > num4)
Was This Post Helpful? 0
  • +
  • -

#4 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1875
  • View blog
  • Posts: 20,282
  • Joined: 17-March 01

Re: if statement

Posted 15 March 2011 - 03:46 PM

That's what the < operator is for, alternatively, you could say num4 > num2 if you're just dead set on using the greater than operator. I'll let someone more familiar with C++ specifically chime in, but I don't believe you can create a conditional using the ! like that. You may be able to do if(!(num2 > num4))??
Was This Post Helpful? 1
  • +
  • -

#5 lokyblue  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 23-March 10

Re: if statement

Posted 15 March 2011 - 03:48 PM

i will try but thanks anyway :)
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is online

  • member icon


Reputation: 4060
  • View blog
  • Posts: 12,540
  • Joined: 25-December 09

Re: if statement

Posted 15 March 2011 - 05:15 PM

You can use the != operator to test for inequality if(num4 != num2).


Jim
Was This Post Helpful? 0
  • +
  • -

#7 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: if statement

Posted 16 March 2011 - 03:34 AM

Lets try some simple logic.

If x is not greater than y then x must be less than or equal to y.

So if you wanted to test for "is not greater than" just use "is less than or equal to". Like this
if(x <= y){
    // do stuff
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1