帕斯卡非法表达
它在第 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您有一个多行
then
块,将其包装在 begin/end 中,它应该可以工作。
You have a multi-line
then
blockWrap it in begin/end and it should work.
更改
为
并将 writeln 语句放入 begin-end 块中。
Change
to
and put the writeln statements in a begin-end block.
你不写; 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.