Link to home
Start Free TrialLog in
Avatar of kenhum
kenhum

asked on

Array's not holding

For some reason this program will not keep track of the arrays info, HELP.

program HockeyStats(Input, Output);


const
    MaxPlayers = 100;

type
    NameArray = array[1..MaxPlayers] of String;
    PositionArray = array[1..MaxPlayers] of Char;
    GoalsArray = array[1..MaxPlayers] of Integer;

var
    Names : NameArray;           {array to record each player's name}
    position : PositionArray;    {array to hold each player's position}
    goals : GoalsArray;          {array to hold number of goals scored}

    HighScoreD,                  {highest score by a defenseman}
    HighScoreFC,                 {highest score by a forward or center}
    NumOfPlayers,                {input - number of players to be entered}
    LoopCount : Integer;         {loop counter/index}

begin
  Write ('Enter the number of players (must be no more than 100) : ');
  Readln (NumOfPlayers);
  Readln (Names[1]);
  Readln (Position[1]);
  Readln (Goals[1]);
  if Position[1] = 'D' then
    HighScoreD := Goals[1];        {highest D}
  if Position[1] = 'C' then
    HighScoreFC := Goals[1];       {highest C}
  if Position[1] = 'F' then
    HighScoreFC := Goals[1];       {highest F}

  for loopcount := 2 to NumOfPlayers do
    begin
      Writeln ('Enter player name, position, and the number of goals scored:');

      Readln (Names[NumOfPlayers]);
      Readln (Position[NumOfPlayers]);
      Readln (Goals[NumOfPlayers]);
      if Position[NumOfPlayers] = 'D' then
        begin
          if Goals[NumOfPlayers] > HighScoreD then
             HighScoreD := Goals[NumOfPlayers]
        end;
      if Position[NumOfPlayers] = 'F' then
        begin
          if Goals[NumOfPlayers] > HighScoreFC then
             HighScoreFC := Goals[NumOfPlayers]
        end;
      if Position[NumOfPlayers] = 'C' then
        begin
          if Goals[NumOfPlayers] > HighScoreFC then
             HighScoreFC := Goals[NumOfPlayers]
        end;

      Writeln;
    end;

  Write ('The highest number of goals by a forward or center is ');
  Writeln (HighScoreFC);
  Writeln ('The following players at these positions scored this number of goals:');
  for LoopCount := 1 to NumOfPlayers do
    begin
      if Goals[NumOfPlayers] = HighScoreFC then
        begin
          if Position[NumOfPlayers] = 'F' then
            Writeln (Names[NumOfPlayers] , ' (' , Position[NumOfPlayers] , ')' );
          if Position[NumOfPlayers] = 'C' then
            Writeln (Names[NumOfPlayers] , ' (' , Position[NumOfPlayers] , ')' );
        end;
    end;
  Writeln;
  Write ('The highest number of goals by a defenseman is ');
  Writeln (HighScoreD);
  Writeln ('The following defenseman scored this number of goals:');
  for LoopCount := 1 to NumOfPlayers do
    begin
      if Goals[NumOfPlayers] = HighScoreD then
        begin
          if Position[NumOfPlayers] = 'D' then
            Writeln (Names[NumOfPlayers] , ' (' , Position[NumOfPlayers] , ')' );
        end;
    end;
end.

ASKER CERTIFIED SOLUTION
Avatar of rwilson032697
rwilson032697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial