它停止在第54和58行编译时出现错误'错误:非法表达'和'语法错误,;期待,但ELSE分别找到了。我的线条位置错了吗?
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;
答案 0 :(得分:5)
您有一个多行then
块
If (NumberOfBalls = 6) Then
Writeln('You have faced 6 balls and compeletd your innings');
Writeln('Your final scoare was: ', CurrentPlayerScore);
Else
将它包裹在开头/结尾,它应该可以正常工作。
答案 1 :(得分:1)
更改
NumberOfBalls = NumberOfBalls + 1
到
NumberOfBalls := NumberOfBalls + 1
并将writeln语句放在开始结束块中。
答案 2 :(得分:0)
你不写;在if句子中的else之前。它结束了整个句子,跳过了其他内容,肯定会给你一个错误。