帕斯卡非法表达

发布于 2024-11-09 01:39:23 字数 3527 浏览 0 评论 0原文

它在第 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;

It stops compiling at lines 54 and 58 with errors 'Error: Illegal expression' and 'Syntax error, ; expected but ELSE found' respectively. Is my position of the lines wrong?

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

辞旧 2024-11-16 01:39:23

您有一个多行 then 块,

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

将其包装在 begin/end 中,它应该可以工作。

You have a multi-line then block

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

Wrap it in begin/end and it should work.

隔岸观火 2024-11-16 01:39:23

更改

NumberOfBalls = NumberOfBalls + 1

NumberOfBalls := NumberOfBalls + 1

并将 writeln 语句放入 begin-end 块中。

Change

NumberOfBalls = NumberOfBalls + 1

to

NumberOfBalls := NumberOfBalls + 1

and put the writeln statements in a begin-end block.

泡沫很甜 2024-11-16 01:39:23

你不写; if 语句中的 else 之前。它结束了整个句子,跳过了 else,这肯定会给你一个错误。

You dont write ; before the else in the if sentence. It ends the whole sentence, skipping the else, and it will surely give you an error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文