我寫了一些代碼下面,我管理它編譯,但它一旦進入球沒有崩潰。開始帕斯卡和需要幫助簡單的程序問題
任何幫助,非常感謝!
我在這篇文章的最後發佈了結構化英語。
Program Game;
var
PlayerOneScore: Integer;
PlayerTwoScore: Integer;
BallsNo: Integer;
CurrentScore: Integer;
Ptr: Integer;
Result:Integer;
Begin
PlayerOneScore:= 0;
PlayerTwoScore:= 0;
Writeln('How many balls do you wish to face?');
Readln(BallsNo);
Ptr:=1;
While Ptr < 1 Do
Begin
Repeat
Ptr:=Ptr+1;
CurrentScore:=0;
Writeln ('Player turn');
Writeln ('Please roll the bowling die');
Writeln ('Enter 1 if result is a 1');
Writeln ('Enter 2 if result is a 2');
Writeln ('Enter 3 if result is a 4');
Writeln ('Enter 4 if result is a 6');
Writeln ('Enter 5 if result is a 0');
While BallsNo >0 Do
Begin
Repeat
BallsNo:=BallsNo-1;
Writeln('This is',BallsNo);
Readln(Result);
If Result = 1 Then
CurrentScore:= CurrentScore+1
Else If Result = 2 THEN
CurrentScore:= CurrentScore+2
Else If Result = 3 THEN
CurrentScore:= CurrentScore+4
Else If Result=4 THEN
CurrentScore := CurrentScore+6
Until BallsNo = 0;
End;
If Ptr = 1 THEN
PlayerOneScore := CurrentScore
Else PlayerTwoScore := CurrentScore;
Until Ptr=2;
End;
If PlayerOneScore > PlayerTwoScore Then
Writeln('Player One Wins');
If PlayerTwoScore > PlayerOneScore Then
Writeln('Player Two Wins');
End.
==================
PlayerOneScore <- 0
PlayerTwoScore <- 0
OUTPUT ‘How many balls do you wish to face?’
INPUT BallsNo
FOR EachPlayer <- 1 TO 2 DO
CurrentScore <- 0
OUTPUT ‘Player’ + EachPlayer + ‘to go’
OUTPUT ‘Please roll the bowling die’
OUTPUT ‘Enter 1 if result is a 1’
OUTPUT ‘Enter 2 if result is a 2’
OUTPUT ‘Enter 3 if result is a 4’
OUTPUT ‘Enter 4 if result is a 6’
OUTPUT ‘Enter 5 if result is a 0’
FOR EachBall <- 1 TO BallsNo DO
OUTPUT ‘Ball number: ‘ + EachBall
INPUT BowlResult
IF BowlResult = 1 THEN
CurrentScore <- CurrentScore + 1
ELSE IF BowlResult = 2 THEN
CurrentScore <- CurrentScore + 2
ELSE IF BowlResult = 3 THEN
CurrentScore <- CurrentScore + 4
ELSE IF BowlReuslt = 4 THEN
CurrentScore <- CurrentScore + 6
END IF
END FOR
IF EachPlayer = 1 THEN
PlayerOneScore <- CurrentScore
ELSE
PlayerTwoScore <- CurrentScore
END FOR
IF PlayerOneScore > PlayerTwoScore THEN
OUTPUT ‘Player One Wins’
ELSE IF PlayerTwoScore > PlayerOneScore THEN
OUTPUT ‘Player Two Wins’
ELSE
OUTPUT ‘Draw’