0

数値の記録を調べてどれが最も高いかを見つける手順をコーディングしようとしています。現在のコードは以下のとおりです。私が抱えている問題は、レコードの最後のスコアをリストしているように見えることです (最高ではありません)。どんな助けでも大歓迎です。

Procedure FindTopScore(Var TopScores : TTopScores);
Var
Count : Integer;
Highest : Integer;
Name: String;

Begin
     For Count := 1 to MaxSize Do
          If TopScores[Count].Score > Highest Then
     Highest := TopScores[Count].Score;
     Name := TopScores[Count].Name;
       Writeln('Higest score is by ' ,TopScores[Count].Name, ' of ', TopScores[Count].Score);
End;
4

3 に答える 3

2

あなたは出力Highestしていませんが、TopScores[Count].Score. 使うだけ

 Writeln('Highest is ', Highest, ' for ', Name);

また、名前をifステートメント内の変数に入れる必要がありますName(実際には外側にあります)。

アドオン:同点の場合にすべての名前が必要な場合は、たとえば次のコードを使用できます

Highest := 0;
For Count := 1 to MaxSize Do Begin
     If TopScores[Count].Score = Highest Then Begin
         Name := Name + ' and ' + TopScores[Count].Name;
     End;
     If TopScores[Count].Score > Highest Then Begin
         Highest := TopScores[Count].Score;
         Name := TopScores[Count].Name;
     End;
 End;
于 2011-05-25T17:55:01.617 に答える
1

ハワードの答えに加えて、ループを開始する前に「0」を「最高」に設定します。初期化されていないため、おそらく最高スコアよりも高い任意の値を持っています。

于 2011-05-25T17:59:22.627 に答える
0

In addition to the accepted answer, make sure you turn on your warnings and hints, and you'll see:

      testhighest.pp(16,39) Warning: Local variable "Highest" does not seem to be initialized

which is the

        If TopScores[Count].Score > Highest Then

line

于 2011-05-28T09:29:21.667 に答える