Plus to Negative value

This is a discussion on Plus to Negative value within the C++ Programming forums, part of the General Programming Boards category; Is there any syntax that will return the opposite value of plus and negative. It should be one syntax that ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    383

    Plus to Negative value

    Is there any syntax that will return the opposite value of plus and negative.
    It should be one syntax that take the opposite. It must work both directions.

    So for these examples:

    Code:
    5       //This will return -5
    -4     //This will return   4

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,734
    Well, if you have a number x, -x is such an opposite.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    383
    That did work actually. So if you just write like in you example a - before x like -x.
    This will make + to - and - to +. I thought that only would work from + to -.
    Then if x is - from the beginning it must be a kind of multiplication -(-x) makes plus I beleive.
    Thanks

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,734
    Then if x is - from the beginning it must be a kind of multiplication -(-x) makes plus I beleive.
    Not multiplication, but just subtraction.
    -(-x) = 0 - (-x) = 0 - (0 - x)
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    383
    Then I think I understand. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Convert bytes to int, keep the negative number
    By umm in forum C Programming
    Replies: 7
    Last Post: 03-20-2009, 04:47 PM
  2. Keep getting negative sign after answer
    By uptown11 in forum C++ Programming
    Replies: 7
    Last Post: 02-23-2009, 10:14 PM
  3. Can we input negative numbers in the output windiw
    By hitesh1511 in forum C Programming
    Replies: 1
    Last Post: 08-22-2006, 12:07 AM
  4. Negative Numbers
    By Quantrizi in forum C++ Programming
    Replies: 7
    Last Post: 10-12-2003, 12:48 AM
  5. how to handle integer overflow in C
    By kate1234 in forum C Programming
    Replies: 8
    Last Post: 04-23-2003, 12:20 PM

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