To all who read last post formatted output

This is a discussion on To all who read last post formatted output within the C Programming forums, part of the General Programming Boards category; What I'm trying to do with formatted output is display the minus sign on the right of the answer not ...

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

    To all who read last post formatted output

    What I'm trying to do with formatted output is display the minus sign on the right of the answer not in front of it which is what will happen by default if I just use the value stored in the variable eg
    Profits = 234.99-
    Any ideas ? I'm lost
    may the source be with you...

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Code:
    if (x<0)
       printf("Profits = %d-",(-x));
    ???

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

    Cool thanx govtcheez

    Thanx for the code it works great
    may the source be with you...

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    No prob - kinda hackish, but it does the job.

  5. #5
    alex
    Guest
    Just another possibility, without the (space-consuming) if:
    printf("Profits = %d%s", x<0?-x:x, x<0?"-":"");

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

    Question alex

    Won't this print a minus sign on both sides of the profit variable x if it is a negative value?
    may the source be with you...

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

    Question alex

    won't this print out a minus sign on both sides of the output if it is negative?
    may the source be with you...

  8. #8
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    It shouldn't do because if x<0 the it prints minus x.

  9. #9
    Unregistered
    Guest
    Look up the 'conditional operator' it is the only ternary operator because it takes 3 operands.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read from file, output random line
    By Asbestos in forum C++ Programming
    Replies: 6
    Last Post: 10-29-2005, 03:53 PM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. No Output? Can someone proof read this please?
    By GrlNewB in forum C++ Programming
    Replies: 4
    Last Post: 07-06-2003, 10:36 PM
  4. formatted output
    By Magica in forum C Programming
    Replies: 3
    Last Post: 05-12-2003, 12:36 AM
  5. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 04:28 PM

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