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
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...
???Code:if (x<0) printf("Profits = £%d-",(-x));
-Govtcheez
[email protected]
Thanx for the code it works great
may the source be with you...
No prob - kinda hackish, but it does the job.
-Govtcheez
[email protected]
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?
may the source be with you...
won't this print out a minus sign on both sides of the output if it is negative?
may the source be with you...
Look up the 'conditional operator' it is the only ternary operator because it takes 3 operands.