couple of issues

This program is suppose to list presidents alphabetically (starting at 0), list their respective chronological order number, and who is their successor's chronum. Here are the issues I'm having.

1. The order is backwards. Not sure why.
2. There is some sort of calculation error at the top of the output.
3. The list is not including John Adams and John Quincy Adams. I'm sure it has something to do with their last name being the same but not sure how to fix it.
4. I don't even know where to start on listing the "next" portion of the code.

Any help is appreciative. Below is my code and output.

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
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

void main()
{
  struct{int chronum; char pname[25]; int next;} plist[50], temp;
  int n=0, i, end, maxindex;

  ifstream fin;
  ofstream fout;
  fin.open("prez.dat");
  fin >> plist[n].pname;
  fout.open("output.dat");

  fout << right << setw(8) << "Alpha #" <<  setw(12) << "Chronum" << setw(25) << "Pres. Name" << setw(8) << "Next" << endl << endl;

  while(!fin.eof())
  {
    plist[n].chronum = n+1;
    n++;
    fin >> plist[n].pname;
  }
  
  for(end=n-1; end>0; end--)
  {
    maxindex = 0;
    for(i=0; i<=end; i++)
    {
      if(strcmp(plist[i].pname, plist[maxindex].pname)>0)
        maxindex=i;
      temp = plist[maxindex];
      plist[maxindex]=plist[end];
      plist[end]=temp;
    }
	fout << right << setw(8) << i << setw(12) << plist[i].chronum << setw(25) << plist[i].pname << setw(8) << /*plist[i].next <<*/ endl;
  }  
}




Alpha #     Chronum               Pres. Name    Next

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