Loops Pascal非法表达式
它在第54行和第58行停止编译,并出现错误“Error:unlikexpression”和“Syntax Error”;预期的,但发现的除外。我的线路位置错了吗Loops Pascal非法表达式,loops,if-statement,pascal,Loops,If Statement,Pascal,它在第54行和第58行停止编译,并出现错误“Error:unlikexpression”和“Syntax Error”;预期的,但发现的除外。我的线路位置错了吗 Procedure PlayDiceGame(PlayerOneName, PlayerTwoName : String; VirtualDiceGame : Boolean; Var TopScores : TTopScores); Var Player
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;
您有一个多行
然后块
If (NumberOfBalls = 6) Then
Writeln('You have faced 6 balls and compeletd your innings');
Writeln('Your final scoare was: ', CurrentPlayerScore);
Else
用begin/end包装它,它应该可以工作。您有一个多行然后
块
If (NumberOfBalls = 6) Then
Writeln('You have faced 6 balls and compeletd your innings');
Writeln('Your final scoare was: ', CurrentPlayerScore);
Else
用begin/end包装它,它应该可以工作。更改
NumberOfBalls = NumberOfBalls + 1
到
并将writeln语句放在begin-end块中。更改
NumberOfBalls = NumberOfBalls + 1
到
然后将writeln语句放在begin-end块中。你不写;在if语句中的else之前。它结束了整个句子,跳过了else,肯定会给你一个错误;在if语句中的else之前。它结束了整个句子,跳过了else,肯定会给您一个错误。Nitpick:添加缺少的分号以正确结束语句。@Turbo J:在Delphi中,您不需要用分号结束语句。您只需要使用分号将两个语句彼此分开。也就是说,begina:=5end
是有效的,但是您需要在begina:=5中使用分号;b:=10 end
Nitpick:添加缺少的分号以正确结束语句。@Turbo J:在Delphi中,不需要用分号结束语句。您只需要使用分号将两个语句彼此分开。也就是说,begina:=5end
是有效的,但是您需要在begina:=5中使用分号;b:=10结束
通常您为i:=0到5 do写(示例),也就是说,do
与
的在同一行上。类似地,如果1+1=2,则通常使用then
在if
的同一行上写入。如果没有文件的其余部分,我们无法确定。但是下面的答案表明这里显示的代码中确实有两个错误。@Andreas Rejbrand:这里的代码格式不是问题,有些地方使用了不同的规则。Jeffs代码(大部分)在语法上是正确的。@Turbo J:是的,当然是。Delphi中的代码格式化总是一个品味问题。但是,由于将do
和then
放在自己的行中是非常少见的,而且由于这样做会使获得“微妙”的细节变得更加困难,例如当您需要使用begin
和end
创建代码块时,我对此进行了评论。当然,我不认为这些问题是由于不寻常地使用空格造成的,而且,如果我相信的话,我会写一个答案而不是评论。JFI:下面是“官方”Pascal(如Delphi)格式指南:通常你为I:=0到5 do写(示例),也就是说,do
与
的位于同一行。类似地,如果1+1=2,则通常使用then
在if
的同一行上写入。如果没有文件的其余部分,我们无法确定。但是下面的答案表明这里显示的代码中确实有两个错误。@Andreas Rejbrand:这里的代码格式不是问题,有些地方使用了不同的规则。Jeffs代码(大部分)在语法上是正确的。@Turbo J:是的,当然是。Delphi中的代码格式化总是一个品味问题。但是,由于将do
和then
放在自己的行中是非常少见的,而且由于这样做会使获得“微妙”的细节变得更加困难,例如当您需要使用begin
和end
创建代码块时,我对此进行了评论。当然,我不认为这些问题是由于不寻常地使用空格造成的,而且,如果我相信这一点,我会写一个答案而不是评论。JFI:以下是“官方”Pascal(如Delphi)格式指南:包装好了,但我得到了;预期错误,但发现错误。@Jeff Howard引用了旧(您的)代码,而不是正确的代码。如果。。。然后开始陈述1;声明2;end else begin语句3;声明4;结束代码>@Eugene谢谢。还要感谢@Andreas用分号解释结束语句;预期错误,但发现错误。@Jeff Howard引用了旧(您的)代码,而不是正确的代码。如果。。。然后开始陈述1;声明2;end else begin语句3;声明4;结束代码>@Eugene谢谢。还要感谢@Andreas用分号解释结束语句。