Solved

Array's not holding

Posted on 1998-11-09
1
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article explains the fundamentals of industrial networking which ultimately is the backbone network which is providing communications for process devices like robots and other not so interesting stuff.
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

627 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