2011-05-21 76 views
1

我一直得到「98/39 comp1_〜1.pas 錯誤:不兼容的類型:得到了」LONGINT「預期的」CHAR「,這是關於第6行。任何幫助請。Pascal:不兼容的類型:得到「LONGINT」預期的「CHAR」

Function RollBowlDie(VirtualDiceGame : Boolean) : Integer; 
    Var 
    BowlDieResult : Char; 
    Begin 
     If VirtualDiceGame 
     Then BowlDieResult := Random(6) + 1 
     Else 
     Begin 
     Repeat 
      Writeln('Please roll the bowling die and then enter your result.'); 
      Writeln; 
      Writeln('Enter 1 if the result is a 1'); 
      Writeln('Enter 2 if the result is a 2'); 
      Writeln('Enter 3 if the result is a 4'); 
      Writeln('Enter 4 if the result is a 6'); 
      Writeln('Enter 5 if the result is a 0'); 
      Writeln('Enter 6 if the result is OUT'); 
      Writeln; 
      Write('Result: '); 
      Readln(BowlDieResult); 
      If not (BowlDieResult in ['1'..'6']) 
      Then 
       Begin 
       Writeln; 
       Writeln('That was not one of the allowed options. Please try agai:'); 
       End; 
      Until BowlDieResult in ['1'..'6']; 
     End; 
RollBowlDie := Ord(BowlDieResult) - Ord('0'); 
    End; 
+0

編譯器告訴你到底是什麼問題。隨機返回一個數字,而BowlDieResult是一個字符。 – CodesInChaos 2011-05-21 11:48:40

回答

2

那麼,有什麼問題嗎?

BowlDieResultchar,但你給它分配一個longint

我帕斯卡是有點生疏,但嘗試

BowlDieResult := chr(49 + Random(6)); 
+0

我明白了!不知道你可以這樣做,謝謝。這個怎麼用?它是否將它解釋爲我接受的字符? – orange 2011-05-21 11:57:25

+0

我假設'chr()'將接受'longint'作爲參數(我認爲是合理的)並將其轉換爲'char'。我還假設Random(6)產生一個範圍在0到5之間的整數,而'chr()'將它轉換爲'0'..'6'。 – pavium 2011-05-21 12:02:38

+0

太棒了!感謝幫助我理解它! – orange 2011-05-21 12:06:41

相關問題