是什么导致了这个问题(Pascal)?

问题描述 投票:0回答:1

我正在编写作业代码,但是编译器总是给我这个过程错误。老实说,我不知道它出了什么问题,我找不到错误。我不知道为什么它给我这个错误。有人有什么想法吗?

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.
pascal freepascal
1个回答
0
投票

在 Pascal 中

and
比比较运算符具有更高的优先级,因此:

WHILE iCount < 16 AND iDecimal > 0 DO

解析更像:

WHILE iCount < (16 AND iDecimal) > 0 DO

比预期的:

WHILE (iCount < 16) AND (iDecimal > 0) DO
© www.soinside.com 2019 - 2024. All rights reserved.