Solved

Array's not holding

Posted on 1998-11-09
1
263 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 50 total points
ID: 1216051
You are using NumOfPlayers in all your array subscripts instead of LoopCount.

Cheers,

Raymond.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Note: This is the second blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   Every month t…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now