2

I am trying to use setw to clean up the output of my program. I want the empty spaces in between "total number of spools to be ordered" and the output.

EDIT this is what im going for:

example output

and this is what I get enter image description here here is what I have so far: UPDATED CODE

/********************************************/
// Name: results                             /
// Description: Print results                /
// Parameters: N/A                           /
// Reture Value: N/A                         /
/********************************************/
void results(int spoolnumber, int subtotalspool, float shippingcost, float totalcost)
{
  cout << left << setw (45) << "Total number of spools to be ordered is: " << right << spoolnumber << endl << endl;

  cout << left << setw (45) << "The subtotal for the spools is:" << right << "$" << subtotalspool << endl << endl;

  cout << "The shipping cost is: $" << shippingcost << endl << endl;

  cout << "The total cost is: $" << totalcost << endl << endl;

  return;
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Sam LaManna
  • 425
  • 2
  • 7
  • 15

1 Answers1

4

You can also do

cout << left << setw (45) <<  "Total number of spools to be ordered is: " << spoolnumber << endl << endl;

to choose which side the padding goes. The default is left.

EDIT: using stringstream

stringstream ss;
ss << "$" << spoolnumber

I think you can fix the right end by adding another setw. So:

cout << left << setw (45) <<  "Total number of spools to be ordered is: " << right << setw(5) << ss.str() << endl << endl;
minus
  • 706
  • 5
  • 14
  • that isnt working either, i included a quick litle example image if that helps make my question more precise. EDIT: duh thats right, i need to use left and not right – Sam LaManna Oct 11 '11 at 17:47
  • that worked kinda, now the zeros dont line up. http://imageshack.us/photo/my-images/198/34267038.png/ I even added << right << after the text strings so the $ and number would be on the right – Sam LaManna Oct 11 '11 at 17:52
  • I think the problem is you are applying the setw to the $ sign. I'm not sure if this is the best way to do it but you can use stringstream to concat $ to the spoolnumber. See edit – minus Oct 11 '11 at 18:47