I'm having trouble using 'setw', 'fixed' and 'setprecision()' to get the output to format as I want. The code below is my payslip class. I have an 'employee' class which this class caters to. It outputs a formatted payslip for each employee (of which there are four). However, once I run the program, the vertical bars placed at the end of each line are planted different for each employee. Is there anyway to ensure the vertical bars sit in place, regardless of the number displaying?
Forgive me if I am explaining this badly.
Any help would be greatly appreciated.
First if the output you're trying to print is larger than the value you supply to setw() you will get the larger output. The setw() function only adds the fill character when the output is smaller than the value. So in your snippet the first setw() probably doesn't appear to do anything.
Next setw() operates on the value immediately following the setw() .
Lastly the setprecision() and fixed manipulators are "sticky" meaning that they stay the same until you change them, so you probably only need these statements once.
You probably should get rid of all those extra spaces in your printout and just use the setw() function properly for all the items.
Hi, thanks a lot for the reply. I used what you've said and have made some progress, 2 of the payslips are outputting as intended. However, a few of the vertical lines in the other 2 payslips are jumbled. (Those being the first and last). Would you have any idea with what's wrong? Output: http://oi64.tinypic.com/5vhw7.jpg