Thread: How to invert an inputted number?

  1. #1

    How to invert an inputted number?

    Hello, and I think this is a very basic question, but I don't know how to take the negative of a number as inputted by the user. I am trying to make a program to do the quadratic formula, in which the user enters a number (b) and the program inverts it to get -b which is then used in the equation. Is it as simple as putting:

    topline1 = -b + (sqrt(discriminant));
    ...or do I need to do something more complicated?


  2. #2
    Registered User
    Join Date
    Mar 2009
    The way you've done it is fine, but you need to be a bit careful so that the result doesn't overflow (signed overflow is undefined). This typically involves making sure that you're not negating INT_MIN or similar.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Guess My Number (Need help)
    By dhardin in forum C++ Programming
    Replies: 5
    Last Post: 12-10-2009, 12:59 PM
  2. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM
  3. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 04:25 AM
  4. parsing a number
    By juancardenas in forum C Programming
    Replies: 1
    Last Post: 02-19-2003, 01:10 PM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM