Using setw()

So im trying to make 2 columns one with name and the other with the price ive been at this for a while but cant seem to get it
[code]

Needs to look like this:
WORDS   $AMOUNT
WORDS   $AMOUNT


No idea how to do it
Last edited on
It's actually really easy, once you get it you probably won't forget. Here's an example of what I believe you are aiming for :

 
cout << WORDS << setw (10) << $AMOUNT << endl;


You're going to have to include <iomanip> as one of the libraries, that's the library that will manipulate the data to display how you see fit. I hope this helps! :)

-a2coding
setw sets the width of the next output so it is more important to use setw before outputting the word.

1
2
3
const int WORD_COLUMN_WIDTH = 8;

cout << setw(WORD_COLUMN_WIDTH) << word << amount << endl;

You could use setw before outputting the amount too but as long as it's left aligned I don't think it's necessary.
Last edited on
Topic archived. No new replies allowed.