Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is causing this issue (Pascal)?

I am writing a code for homework, however, the compiler always gives me this error for the Procedure. I honestly have no idea what is wrong about it, I can not 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 // the error should be in this line???
  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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading