標題:
pascal program問題
發問:
sample output1(assume the die has 6 face) Enter your guess (O)dd, (E)ven? O die 1 =4 die 2 =6 die 3 =6 sum =16 sorry,you lose! sample output2 Enter your guess (O)dd, (E)ven? abc invalue input Enter your guess (O)dd, (E)ven? E die 1 =6 die 2 =5 die 3 =3 sum =14 you win!
最佳解答:
A simple Pascal program for your reference: [ Try to use array and for loop to write a better program. ] var die1, die2, die3, sum : real; guess, evenodd : string; begin randomize; repeat write('Enter your guess (O)dd, (E)ven? '); readln(guess); if (guess'O') and (guess'E') then writeln('Invalid input'); until (guess='O') or (guess='E'); die1:=int(random*6)+1; die2:=int(random*6)+1; die3:=int(random*6)+1; sum:=die1+die2+die3; writeln('die1=', die1:0:0); writeln('die2=', die2:0:0); writeln('die3=', die3:0:0); writeln('sum=', sum:0:0); if int(sum/2)*2=sum then evenodd:='E' else evenodd:='O'; if guess=evenodd then writeln('You win!') else writeln('Sorry, you lose!'); end.
此文章來自奇摩知識+如有不便請留言告知
其他解答:
留言列表