making output look nice

i have a program where i what the out put to have the headers horizontally and the out put centered underneath. i have it figured out for the max numbers that will displayed but if it goes less it compresses so the output isn't even under the proper header.How can i get the max and min to line up neatly under the header here is the code with the output displayed on screen:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
	   cout <<"Batting Stats"<<"\n";
       cout <<"\n\n\n";
       cout<<"AT BATS RUNS SCORED  TOTAL HITS   SINGLES    DOUBLES   TRIPLES    HOME RUNS"<<"\n";
	   cout<<" "<<atbats <<"      "<<runs<<"           "<<totalhits<<"        "<<single<<"        "<<doubles;
	   cout <<"       "<<triples<<"        "<<homeruns<<"\n\n";
       cout<<"RBI   TOTAL BASES    WALKS    STRIKEOUTS  STOLEN BASES  CAUGHT STEALING  TOTAL STOLEN BASES"<<"\n";
	   cout<<runbatin<<"        "<<totalbases<<"     "<<walks<<"      "<<strikeouts<<"    "<<steals<<"      "<<caughtsteal;
	   cout<<total_sba<<"\n\n";
	   cout<<"SB %   OBP %  SLUG %  BAVG"<<"\n";
	   cout<<fixed<<setprecision(2)<<sbper<<"    "<<fixed<<setprecision(3)<<onbaseper<<"    "<<fixed<<setprecision(3)<<slugper<<"    ";
	   cout<<fixed<<setprecision(3)<<bavg<<"\n";
	   cout<<"SAC FLIES   SAC HITS  HIT PITCH  IBB  DOUBLE PLAY  PLATE APPEAR   # OF PITCHES EXTRA BASE HITS";
       cout<<" "<<sacfly<<"    "<<sachits<<"     "<<hitp<<"    "<<intwalk<<"   "<<gdoubleplay<<"   "<<plateappear<<"    ";
	   cout<<numpitch<<"    "<<xbasehits<<"\n\n";
	   cout<<"GROUND OUTS   FLY OUTS   GO/FO   OPS    DEFENSIVE INTERFERENCE  RUNS BY SB  K/BB  ISO POWER    RUNS CREATED";
	   cout<<groundout<<"       "<<flyout<<"    "<<fixed<<setprecision(3)<<gofor<<"    "<<fixed<<setprecision(3)<<onbaseslgper;
	   cout<<"    "<<dinterfer<<"     "<<fixed<<setprecision(1)<<sbruns<<"   "<<fixed<<setprecision(3)<<soratio;
	   cout<<fixed<<setprecision(3)<<isopower<<"     "<<fixed<<setprecision(2)<<runscre;
	   cout<<"\n\n\n";

Also how do i make the console display full screen?
Thank you in advance for any help anyone can give me.
Last edited on
Use <iomanip> and setw().

Example:
1
2
cout<<"AT BATS RUNS SCORED  TOTAL HITS   SINGLES    DOUBLES   TRIPLES    HOME RUNS"<<"\n";
cout << setw(7) << atbats << " "<< setw(11) << runs << " " << setw(10) << totalhits << " " << setw(7) << single << " " << setw(7) << doubles << " "; // Continue on from here.  


What it does is I counted the number of characters long each word/phrase was and made that the width. Then I added a space and repeated the process.

Tutorial on getting fullsreen
http://www.associatedcontent.com/article/1167948/how_to_make_your_c_console_application.html
You may need to include <windows.h>. I'm not sure.

Last edited on
Thank you eker676 i have tried your 1st solution and it works great just have to play around with the numbers some but it work for got about that i even was looking at the tutorial on setw and just didn't recognize that it would work for me. have bookmarked the other part of my problem and will get back to that one. Thanks again for your help
Topic archived. No new replies allowed.