標題:

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.

免費註冊體驗

 

此文章來自奇摩知識+如有不便請留言告知

其他解答:

arrow
arrow
    文章標籤
    行星 文章 香橙 奇摩
    全站熱搜
    創作者介紹
    創作者 rll33xb99t 的頭像
    rll33xb99t

    rll33xb99t的部落格

    rll33xb99t 發表在 痞客邦 留言(0) 人氣()