Solved

Array's not holding

Posted on 1998-11-09
1
262 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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