pascalfreepascal

What is causing this? Error: Incompatible types: got "Boolean" expected "LongInt"


I am writing code for homework, however, the compiler always gives me the following error for the procedure. I honestly have no idea what is wrong about it, I cannot find the mistake. I don't know why it's giving me this error. Does anyone have any idea?

convertNumbers.pas(21,14) Error: Incompatible types: got "Boolean" expected "LongInt"

convertNumbers.pas(42,4) Fatal: There were 1 errors compiling module, stopping

PROGRAM convertNumbers;

TYPE
  aDual = ARRAY[0..15] OF BOOLEAN;

PROCEDURE Dual2Dec (iDecimal: INTEGER; VAR aDualCalc: aDual);
VAR
  iCount: INTEGER;
  bDivision: BOOLEAN;
  iCalculation: INTEGER;

BEGIN
  iCount := 0;    

  WHILE iCount < 16 AND iDecimal > 0 DO  // Error: Incompatible types: got "Boolean" expected "LongInt"
  BEGIN
    iCalculation := iDecimal mod 2;
    IF iCalculation = 0 THEN
      bDivision := FALSE
    ELSE
      bDivision := TRUE;
    aDualCalc[iCount] := bDivision;
    iDecimal := iDecimal div 2;
    iCount := iCount + 1;
  END;
END;

BEGIN

END.

Solution

  • In Pascal and has higher precedence than comparison operators, so:

    WHILE iCount < 16 AND iDecimal > 0 DO
    

    Parses more like:

    WHILE iCount < (16 AND iDecimal) > 0 DO
    

    Than the intended:

    WHILE (iCount < 16) AND (iDecimal > 0) DO