Pascal: Incompatible types: got “LONGINT” expected “CHAR”

江枫思渺然 提交于 2020-01-24 21:37:15

问题


I keep getting the "98 / 39 comp1_~1.pas Error: Incompatible types: got "LONGINT" expected "CHAR". This is concerning line 6. Any help please.

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;

回答1:


So what's the problem?

BowlDieResult is a char but you're assigning a longint to it.

My pascal is a bit rusty, but try

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


来源:https://stackoverflow.com/questions/6081367/pascal-incompatible-types-got-longint-expected-char

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!