Hey there. I've been working on a specific lab for a week now and I cant seem to figure out how to get the output to do what I need it to do. In this lab I'm having to enter some employee data from the keyboard, do some calculations to the data and print the output to a file before new employee data is added to the program. The problem i'm running into is I need to be able to put a "$" infront of some numbers that are being generated by the calculations.
I'm using fprintf to print the output to a file.
for instance this is what i need it to look like:
emp1 (other data) (other data) -----$65.09
emp2 (other data) (other data) ----$102.09
emp3 (other data) (other data) --$1104.04 (the decimal place has to line up vertically. disregard the ---'s, they are suppose to be whitespaces)
However, I personally have only been able to come up with two forms of output and neither are what I need them to be.
$"%.2lf" gives me:
emp1 (other data) (other data) $65.09
emp2 (other data) (other data) $102.09
emp3 (other data) (other data) $1104.04
and $"%8.2lf" gives me:
emp1 (other data) (other data) $-----65.09
emp2 (other data) (other data) $---102.09
emp3 (other data) (other data) $-1104.04 (again disregard the ---'s, they are suppose to be whitespaces)
I've also tried $"%-8.2lf" but that gives me the same output as $"%.2lf". Everything else for the lab is completed expect for this problem I'm having. If anyone could chime in and give me some pointers on how to accomplish this task I would greatly appreciate it.
I'm using fprintf to print the output to a file.
for instance this is what i need it to look like:
emp1 (other data) (other data) -----$65.09
emp2 (other data) (other data) ----$102.09
emp3 (other data) (other data) --$1104.04 (the decimal place has to line up vertically. disregard the ---'s, they are suppose to be whitespaces)
However, I personally have only been able to come up with two forms of output and neither are what I need them to be.
$"%.2lf" gives me:
emp1 (other data) (other data) $65.09
emp2 (other data) (other data) $102.09
emp3 (other data) (other data) $1104.04
and $"%8.2lf" gives me:
emp1 (other data) (other data) $-----65.09
emp2 (other data) (other data) $---102.09
emp3 (other data) (other data) $-1104.04 (again disregard the ---'s, they are suppose to be whitespaces)
I've also tried $"%-8.2lf" but that gives me the same output as $"%.2lf". Everything else for the lab is completed expect for this problem I'm having. If anyone could chime in and give me some pointers on how to accomplish this task I would greatly appreciate it.
Last edited: