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
Printable View
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
???Code:if (x<0)
printf("Profits = £%d-",(-x));
Thanx for the code it works great
:cool:
No prob - kinda hackish, but it does the job.
Just another possibility, without the (space-consuming) if:
printf("Profits = £%d%s", x<0?-x:x, x<0?"-":"");
Won't this print a minus sign on both sides of the profit variable x if it is a negative value?
:confused:
won't this print out a minus sign on both sides of the output if it is negative?
:confused:
It shouldn't do because if x<0 the it prints minus x.
Look up the 'conditional operator' it is the only ternary operator because it takes 3 operands.