Error handling Pascal:不兼容类型:Get";“长”字;“预期”;CHAR";

Error handling Pascal:不兼容类型:Get";“长”字;“预期”;CHAR";,error-handling,char,pascal,Error Handling,Char,Pascal,我一直在得到“98/39”的补偿 错误:不兼容的类型:获取“LONGINT”预期为“CHAR”。这与第6行有关。请提供任何帮助 Function RollBowlDie(VirtualDiceGame : Boolean) : Integer; Var BowlDieResult : Char; Begin If VirtualDiceGame Then BowlDieResult := Random(6) + 1 Else B

我一直在得到“98/39”的补偿 错误:不兼容的类型:获取“LONGINT”预期为“CHAR”。这与第6行有关。请提供任何帮助

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;
那有什么问题

bowldiesult
是一个
char
但您正在为其分配一个
longint

我的帕斯卡有点生锈了,但是试试看

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

编译器确切地告诉了您问题所在。Random返回一个数字,而BowlDieResult是一个字符。我明白了!不知道您可以这样做,谢谢。这是如何工作的?它是否解释为字符我接受它?我假设
chr()
将接受
longint
作为参数(我认为合理)我还假设
Random(6)
生成一个范围为0..5的整数,
chr()
将其转换为“0”..6”。太棒了!谢谢你帮助我理解它!不客气。我应该说“the
chr()
将其转换为“1”..6”。但你可能意识到了这一点。