Паскаль Нелегальное Выражение - PullRequest
0 голосов
/ 21 мая 2011

Останавливает компиляцию в строках 54 и 58 с ошибками «Ошибка: недопустимое выражение» и «Ошибка синтаксиса»;ожидается, но еще найден 'соответственно.Моя позиция линий неправильна?

Procedure PlayDiceGame(PlayerOneName, PlayerTwoName : String;
                           VirtualDiceGame : Boolean; Var TopScores : TTopScores);
      Var
        PlayerOut : Boolean;
        CurrentPlayerScore : Integer;
        AppealDieResult : Integer;
        PlayerNo : Integer;
        PlayerOneScore : Integer;
        PlayerTwoScore : Integer;
        BowlDieResult : Integer;
        RunsScored : Integer;
        NumberOfBalls : Integer;
      Begin
        For PlayerNo := 1 To 2
          Do
            Begin
            NumberOfBalls := 0;
              CurrentPlayerScore := 0;
              PlayerOut := False;
              If PlayerNo = 1
                Then Writeln(PlayerOneName, ' is batting')
                Else Writeln(PlayerTwoName, ' is batting');
              Writeln;
              Writeln('Press the Enter key to continue');
              Readln;
              Repeat
                BowlDieResult := RollBowlDie(VirtualDiceGame);
                If BowlDieResult In [1..4]
                  Then
                    Begin
                      RunsScored := CalculateRunsScored(BowlDieResult);
                      DisplayRunsScored(RunsScored);
                      CurrentPlayerScore := CurrentPlayerScore + RunsScored;
                      Writeln('Your new score is: ', CurrentPlayerScore);
                    End;
                If BowlDieResult = 5
                  Then Writeln('No runs scored this time.  Your score is still: ',
                              CurrentPlayerScore);
                If BowlDieResult = 6
                  Then
                    Begin
                      Writeln('This could be out... press the Enter key to find out.');
                      Readln;
                      AppealDieResult := RollAppealDie(VirtualDiceGame);
                      DisplayAppealDieResult(AppealDieResult);
                      If AppealDieResult >= 2
                        Then PlayerOut := True
                        Else PlayerOut := False;
                    End;
                Writeln;
                Writeln('Press the Enter key to continue');
                Readln;
                NumberOfBalls = NumberOfBalls + 1
              Until PlayerOut or (NumberOfBalls = 6);
              If (NumberOfBalls = 6) Then
              Writeln('You have faced 6 balls and compeletd your innings');
              Writeln('Your final scoare was: ', CurrentPlayerScore);
              Else
              Writeln('You are out.  Your final score was: ', CurrentPlayerScore);
              Writeln;
              Writeln('Press the Enter key to continue');
              Readln;
              If PlayerNo = 1
                Then PlayerOneScore := CurrentPlayerScore
                Else PlayerTwoScore := CurrentPlayerScore;
            End;
        DisplayResult(PlayerOneName, PlayerOneScore, PlayerTwoName, PlayerTwoScore);
        If (PlayerOneScore >= PlayerTwoScore)
          Then
            Begin
              UpdateTopScores(TopScores, PlayerOneName, PlayerOneScore);
              UpdateTopScores(TopScores, PlayerTwoName, PlayerTwoScore);
            End
          Else
            Begin
              UpdateTopScores(TopScores, PlayerTwoName, PlayerTwoScore);
              UpdateTopScores(TopScores, PlayerOneName, PlayerOneScore);
            End;
        Writeln;
        Writeln('Press the Enter key to continue');
        Readln;
      End;

Ответы [ 3 ]

5 голосов
/ 21 мая 2011

У вас есть многострочный then блок

If (NumberOfBalls = 6) Then
    Writeln('You have faced 6 balls and compeletd your innings');
    Writeln('Your final scoare was: ', CurrentPlayerScore);
Else

Заверните его в начало / конец, и он должен работать.

1 голос
/ 21 мая 2011

Измените

NumberOfBalls = NumberOfBalls + 1

на

NumberOfBalls := NumberOfBalls + 1

и поместите записываемые операторы в блок конца-конца.

0 голосов
/ 13 марта 2013

Вы не пишете; перед остальным в предложении if. Он заканчивает целое предложение, пропуская остальное, и, несомненно, даст вам ошибку.

...