I have a homework problem we are supposed to output to a file and the data values are supposed to be right aligned which I thought it was supposed to be by default. I don't know what to do here.
If you do calculate how many digits a value to print will have, then you can calculate how many whitespace characters must be printed first in order to produce the desired total column width.
Edit: Or not. Your actual problem is the $.
1 2 3 4
outfile.width(N);
[code]outfile << "$"; // print the '$' with N-1 whitespace before it
outfile << total; // no width is set for this
In ideal case
1 2
outf << 42;
$42.00
In other words: the $ is part of the number format and then the ostream::width work nicely. Such output formatting has never been necessary to me, so I cannot point to proper direction. You probably have to do the math, if <iostream> is the only allowed part of the standard library.