iomanip and setw

This is the code I have
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>

using namespace std;
void main()
{
	ifstream fin;
	struct { int chronum; string pname; int next; } plist[50], temp;
	int n=0, bottom, imax, i, j;
	fin.open("prez.dat");
	fin>>plist[n].pname;  //reads in the first prez name
	while (!fin.eof())
	{
		plist[n].chronum=n+1;  //sets the value of the chronum to the position he was in office
		n++;  //increments n to the next number for the next prez
		fin>>plist[n].pname;  //reads in the next prez and sets in in slot [n].  note...last n is 44

		/*sort via selectmax sort*/
	}
	for
		(bottom= n-1; bottom>0; bottom--)
	{
		imax=0;
		for(i=1; i<= bottom; i++)
			if (plist[i].pname > plist[imax].pname)
				imax=i;
		temp = plist[imax];
		plist[imax] = plist[bottom];
		plist[bottom] = temp;
	} 

	cout<<setw(15)<<"Location"<<setw(15)<<"Chronum"<<setw(30)<<"President's name"<<setw(15)<<"Pointer"<<endl;
	for(i = 0; i<=43; i++)
	{
		if(plist[i].chronum == n)		//If pres is Obama set next to -1
		{
			plist[i].next = -1;	
		} 
		else
		{
			for(int j=0; j<=43; j++)		// loop through the list of presidents 
			{
				if(plist[j].chronum == plist[i].chronum+1) // for every president loop through the list again and find the president  that comes after him
				{
					plist[i].next = j;		// set next to the location of the president after him		
				}
			}
		}
		
		cout<<setw(15)<< i <<setw(15)<<plist[i].chronum <<setw(30)<<plist[i].pname <<setw(15)<<plist[i].next << endl;	
	}


}

and here is my output


       Location        Chronum              President's name        Pointer
              0              2                    ADAMS,JOHN             22
              1              6             ADAMS,JOHN_QUINCY             21
              2             21                ARTHUR,CHESTER              7
              3             15                BUCHANAN,JAMES             26
              4             41                   BUSH,GEORGE              9
              5             43            BUSH,GEORGE_WALKER             31
              6             39                  CARTER,JIMMY             34
              7             22              CLEVELAND,GROVER             17
              8             24             CLEVELAND2,GROVER             28
              9             42               CLINTON,WILLIAM              5
             10             30               COOLIDGE,CALVIN             20
             11             34             EISENHOWER,DWIGHT             25
             12             13              FILLMORE,MILLARD             32
             13             38                   FORD,GERALD              6
             14             20                GARFIELD,JAMES              2
             15             18                 GRANT,ULYSSES             19
             16             29                HARDING,WARREN             10
             17             23             HARRISON,BENJAMIN              8
             18              9        HARRISON,WILLIAM_HENRY             40
             19             19              HAYES,RUTHERFORD             14
             20             31                HOOVER,HERBERT             35
             21              7                JACKSON,ANDREW             41
             22              3              JEFFERSON,THOMAS             27
             23             17                JOHNSON,ANDREW             15
             24             36                JOHNSON,LYNDON             30
             25             35                  KENNEDY,JOHN             24
             26             16               LINCOLN,ABRAHAM             23
             27              4                 MADISON,JAMES             29
             28             25              MCKINLEY,WILLIAM             36
             29              5                  MONROE,JAMES              1
             30             37                 NIXON,RICHARD             13
             31             44                  OBAMA,BARACK             -1
             32             14               PIERCE,FRANKLIN              3
             33             11                    POLK,JAMES             38
             34             40                 REAGAN,RONALD              4
             35             32            ROOSEVELT,FRANKLIN             39
             36             26            ROOSEVELT,THEODORE             37
             37             27           TAFT,WILLIAM_HOWARD             43
             38             12                TAYLOR,ZACHARY             12
             39             33                  TRUMAN,HARRY             11
             40             10                    TYLER,JOHN             33
             41              8              VAN_BUREN,MARTIN             18
             42              1             WASHINGTON,GEORGE              0
             43             28                WILSON,WOODROW             16


Now what the problem is, is that the names need to be lined up with the left of "president's name" can someone help me out with this. i dont know whats going on
Last edited on
when I add a Left this is what I get


       Location        Chronum              President's name        Pointer
              0              2                    ADAMS,JOHN22
1              6              ADAMS,JOHN_QUINCY             21
2              21             ARTHUR,CHESTER                7
3              15             BUCHANAN,JAMES                26
4              41             BUSH,GEORGE                   9
5              43             BUSH,GEORGE_WALKER            31
6              39             CARTER,JIMMY                  34
7              22             CLEVELAND,GROVER              17
8              24             CLEVELAND2,GROVER             28
9              42             CLINTON,WILLIAM               5
10             30             COOLIDGE,CALVIN               20
11             34             EISENHOWER,DWIGHT             25
12             13             FILLMORE,MILLARD              32
13             38             FORD,GERALD                   6
14             20             GARFIELD,JAMES                2
15             18             GRANT,ULYSSES                 19
16             29             HARDING,WARREN                10
17             23             HARRISON,BENJAMIN             8
18             9              HARRISON,WILLIAM_HENRY        40
19             19             HAYES,RUTHERFORD              14
20             31             HOOVER,HERBERT                35
21             7              JACKSON,ANDREW                41
22             3              JEFFERSON,THOMAS              27
23             17             JOHNSON,ANDREW                15
24             36             JOHNSON,LYNDON                30
25             35             KENNEDY,JOHN                  24
26             16             LINCOLN,ABRAHAM               23
27             4              MADISON,JAMES                 29
28             25             MCKINLEY,WILLIAM              36
29             5              MONROE,JAMES                  1
30             37             NIXON,RICHARD                 13
31             44             OBAMA,BARACK                  -1
32             14             PIERCE,FRANKLIN               3
33             11             POLK,JAMES                    38
34             40             REAGAN,RONALD                 4
35             32             ROOSEVELT,FRANKLIN            39
36             26             ROOSEVELT,THEODORE            37
37             27             TAFT,WILLIAM_HOWARD           43
38             12             TAYLOR,ZACHARY                12
39             33             TRUMAN,HARRY                  11
40             10             TYLER,JOHN                    33
41             8              VAN_BUREN,MARTIN              18
42             1              WASHINGTON,GEORGE             0
43             28             WILSON,WOODROW                16

Topic archived. No new replies allowed.