Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Array's not holding

Posted on 1998-11-09
1
Medium Priority
?
274 Views
Last Modified: 2011-08-18
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.

0
Comment
Question by:kenhum
1 Comment
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 200 total points
ID: 1216051
You are using NumOfPlayers in all your array subscripts instead of LoopCount.

Cheers,

Raymond.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Take a look at these 6 Outlook Email management tools which can augment the working and performance of Microsoft Outlook to give you a more rewarding emailing experience.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question