plus minus ? need help

This is a discussion on plus minus ? need help within the C Programming forums, part of the General Programming Boards category; Hi I wish to write code that has a condition that I dont want to accecpt anything in which the ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    15

    plus minus ? need help

    Hi I wish to write code that has a condition that I dont want to accecpt anything in which the sum is plus or minus 2.
    I have written this

    ge_event_id[0]-ge_event_id[1]!=+-2

    but I dont think it works.
    Does anyone know if you can use !=+- or is there any other operator or method that does this.

    Cheers

  2. #2
    Registered User
    Join Date
    Jun 2010
    Posts
    45
    how about using the absolute value of (ge_event_id[0]-ge_event_id[1]) != 2

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    15
    Would that be the same as writing
    ge_event_id[0]-ge_event_id[1]!=-2 && ge_event_id[0]-ge_event_id[1]!=+2

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    I believe he's referring to the abs() macro in stdio.h. In your case it will return 2 for both -2 and 2. You could then test just for 2.

    You could perhaps do what you are showing above as well, but you will need OR instead of AND "ge_event_id" can never be both -2 and 2 at the same time.

  5. #5
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    abs() is in stdlib.h

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 08-23-2009, 09:52 AM
  2. Replies: 1
    Last Post: 08-04-2008, 06:34 PM
  3. ASCII code goes into minus
    By Degenko in forum C Programming
    Replies: 4
    Last Post: 05-26-2007, 01:35 PM
  4. << operator and the minus before brackets
    By cblix in forum C Programming
    Replies: 8
    Last Post: 10-25-2005, 07:14 PM
  5. Problem with unary minus overloading
    By Strait in forum C++ Programming
    Replies: 7
    Last Post: 01-14-2005, 02:42 PM

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