Feb 22, 2017 at 3:37am Feb 22, 2017 at 3:37am UTC
Hey guys,
I need formatting help with my output.
Here's a snippet of my code.
1 2 3 4 5 6
cout << left << StockName << ' ' ;
cout << setw(8) << right << NUMofShares << ' ' ;
cout << fixed << setprecision(2);
cout << setw(9) << right << PurchasePrice << ' ' ;
cout << setw(9) << right << SalePrice << ' ' ;
cout << setw(14) << right << ProfitOrLoss << endl;
I want my output to look like this below.
1 2 3 4 5 6
Stock Shares P Price S Price Profit (Loss)
_____ ______ _______ _______ _____________
AAPL 23 102.30 96.25 -157.05
GE 15 23.00 28.87 70.15
MSFT 30 58.50 52.06 -213.10
GOOG 10 540.20 695.03 1528.40
But in reality it looks like this... (Below) :(
1 2 3 4 5 6
Stock Shares P Price S Price Profit (Loss)
_____ ______ _______ _______ _____________
AAPL 23 102.30 96.25 -157.05
GE 15 23.00 28.87 70.15
MSFT 30 58.50 52.06 -213.10
GOOG 10 540.20 695.03 1528.40
How can I fix this? The shorter Stock name is creating this issue for me.
Ex: GE.
How can I make the stock name stay in place as left aligned and have no effect on the setw for the numerical values?
Thanks,
MisterTams
Last edited on Feb 22, 2017 at 3:38am Feb 22, 2017 at 3:38am UTC
Feb 22, 2017 at 3:57am Feb 22, 2017 at 3:57am UTC
Thanks Mantorr22!
Works great!