formatting output

This is a discussion on formatting output within the C Programming forums, part of the General Programming Boards category; I am trying to write a prog that will allow input of float values and calculate profits from these values.I ...

  1. #1
    Registered User spliff's Avatar
    Join Date
    Aug 2001
    Posts
    14

    Unhappy formatting output

    I am trying to write a prog that will allow input of float values and calculate profits from these values.I need to be able to print out a minus sign if the profits are negative and the '-' has to be on the right hand side of the output value.I have worked out that you can print a minus on the right by using %5.2f- but I need to test the value stored in the variable.
    i.e
    (if value<0)
    Use %5.2f-
    else
    use %5.2f
    Is there an easy way to tell if the value stored in the variable is negative so I can use this format specifier .
    What I'd like to do is use the ternary operator e.g.
    (value<0) ? %5.2f- : %5.2f ; but this doesn't work
    Any ideas gents?(or ladies(College Girl))
    may the source be with you...

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    I'm not sure that I understand. If the value is negative, it will print as negative value (with the minus sign) you wont need to add a '-' character.

    If you want to change the sign you could do

    if (loss)
    value = -value;

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    27
    Yeah if the value is negative it will reflect this in were ever store the value.

    I might not be understanding your question.
    -ali

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Connecting input iterator to output iterator
    By QuestionC in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2007, 03:18 AM
  2. Switch statement and returning the correct output
    By slowcoder in forum C Programming
    Replies: 6
    Last Post: 09-28-2006, 05:00 PM
  3. Formatting output to screen from a file
    By clearrtc in forum C Programming
    Replies: 2
    Last Post: 08-20-2006, 04:19 PM
  4. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 02:11 AM
  5. dos game help
    By kwm32 in forum Game Programming
    Replies: 7
    Last Post: 03-28-2004, 06:28 PM

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