Linear equation, incompatible types BOOLEAN/LONGINT












0















I've got exercise about linear equation in Pascal and I've created simple code for comparison input numbers but when I try to run it. I have problem about incompatible types, got BOOLEAN and expected LONGINT.



program LinearEquation;

var
a, b: real;

begin
readln(a, b);

if (b = 0 and a = 0) then
writeln('INFINITY')
else if (b = 0 and a <> 0) then
writeln(1)
else if (a = 0 and b <> 0) then
writeln(0)
else if(b mod a = 0) then
writeln(1);

readln;

end.


and



13 / 9 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"
15 / 14 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"
17 / 14 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"
17 / 14 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"









share|improve this question




















  • 2





    Read up about the precedence of operators, or just add more (). The rules for operator precedence vary with languages. Note that the outer () in if statements are redundant in Pascal.

    – Marco van de Voort
    Nov 23 '18 at 10:55








  • 1





    ...in other words, you want if (b=0) and (a=0) ...

    – linuxfan
    Nov 23 '18 at 14:18
















0















I've got exercise about linear equation in Pascal and I've created simple code for comparison input numbers but when I try to run it. I have problem about incompatible types, got BOOLEAN and expected LONGINT.



program LinearEquation;

var
a, b: real;

begin
readln(a, b);

if (b = 0 and a = 0) then
writeln('INFINITY')
else if (b = 0 and a <> 0) then
writeln(1)
else if (a = 0 and b <> 0) then
writeln(0)
else if(b mod a = 0) then
writeln(1);

readln;

end.


and



13 / 9 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"
15 / 14 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"
17 / 14 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"
17 / 14 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"









share|improve this question




















  • 2





    Read up about the precedence of operators, or just add more (). The rules for operator precedence vary with languages. Note that the outer () in if statements are redundant in Pascal.

    – Marco van de Voort
    Nov 23 '18 at 10:55








  • 1





    ...in other words, you want if (b=0) and (a=0) ...

    – linuxfan
    Nov 23 '18 at 14:18














0












0








0








I've got exercise about linear equation in Pascal and I've created simple code for comparison input numbers but when I try to run it. I have problem about incompatible types, got BOOLEAN and expected LONGINT.



program LinearEquation;

var
a, b: real;

begin
readln(a, b);

if (b = 0 and a = 0) then
writeln('INFINITY')
else if (b = 0 and a <> 0) then
writeln(1)
else if (a = 0 and b <> 0) then
writeln(0)
else if(b mod a = 0) then
writeln(1);

readln;

end.


and



13 / 9 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"
15 / 14 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"
17 / 14 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"
17 / 14 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"









share|improve this question
















I've got exercise about linear equation in Pascal and I've created simple code for comparison input numbers but when I try to run it. I have problem about incompatible types, got BOOLEAN and expected LONGINT.



program LinearEquation;

var
a, b: real;

begin
readln(a, b);

if (b = 0 and a = 0) then
writeln('INFINITY')
else if (b = 0 and a <> 0) then
writeln(1)
else if (a = 0 and b <> 0) then
writeln(0)
else if(b mod a = 0) then
writeln(1);

readln;

end.


and



13 / 9 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"
15 / 14 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"
17 / 14 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"
17 / 14 rownan~1.pas
Error: Incompatible types: got "BOOLEAN" expected "LONGINT"






pascal operator-precedence






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 11:51









Andreas Rejbrand

72.4k6208302




72.4k6208302










asked Nov 23 '18 at 10:45









Rav3Rav3

559




559








  • 2





    Read up about the precedence of operators, or just add more (). The rules for operator precedence vary with languages. Note that the outer () in if statements are redundant in Pascal.

    – Marco van de Voort
    Nov 23 '18 at 10:55








  • 1





    ...in other words, you want if (b=0) and (a=0) ...

    – linuxfan
    Nov 23 '18 at 14:18














  • 2





    Read up about the precedence of operators, or just add more (). The rules for operator precedence vary with languages. Note that the outer () in if statements are redundant in Pascal.

    – Marco van de Voort
    Nov 23 '18 at 10:55








  • 1





    ...in other words, you want if (b=0) and (a=0) ...

    – linuxfan
    Nov 23 '18 at 14:18








2




2





Read up about the precedence of operators, or just add more (). The rules for operator precedence vary with languages. Note that the outer () in if statements are redundant in Pascal.

– Marco van de Voort
Nov 23 '18 at 10:55







Read up about the precedence of operators, or just add more (). The rules for operator precedence vary with languages. Note that the outer () in if statements are redundant in Pascal.

– Marco van de Voort
Nov 23 '18 at 10:55






1




1





...in other words, you want if (b=0) and (a=0) ...

– linuxfan
Nov 23 '18 at 14:18





...in other words, you want if (b=0) and (a=0) ...

– linuxfan
Nov 23 '18 at 14:18












1 Answer
1






active

oldest

votes


















2














At least in modern Delphi, and has higher precedence than =, so



a = 0 and b = 0


is interpreted as



(a = (0 and b)) = 0.


But the and operator cannot accept an integer and a floating-point value as operands (two integers would have been OK, though). Hence the error.



Had a and b been integers, 0 and b would have been the bitwise conjunction of 0 and b, that is, 0. Thus, we would have had



(a = 0) = 0.


This reads either true = 0 (if a is equal to 0) or false = 0 (if a is different from 0). But a boolean cannot be compared to an integer, so the compiler would have complained about that.



Still, this was just an academic exercise. Clearly, your intension was



(a = 0) and (b = 0).


Just add the parentheses:



if (b = 0) and (a = 0) then
writeln('INFINITY')





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445189%2flinear-equation-incompatible-types-boolean-longint%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    At least in modern Delphi, and has higher precedence than =, so



    a = 0 and b = 0


    is interpreted as



    (a = (0 and b)) = 0.


    But the and operator cannot accept an integer and a floating-point value as operands (two integers would have been OK, though). Hence the error.



    Had a and b been integers, 0 and b would have been the bitwise conjunction of 0 and b, that is, 0. Thus, we would have had



    (a = 0) = 0.


    This reads either true = 0 (if a is equal to 0) or false = 0 (if a is different from 0). But a boolean cannot be compared to an integer, so the compiler would have complained about that.



    Still, this was just an academic exercise. Clearly, your intension was



    (a = 0) and (b = 0).


    Just add the parentheses:



    if (b = 0) and (a = 0) then
    writeln('INFINITY')





    share|improve this answer




























      2














      At least in modern Delphi, and has higher precedence than =, so



      a = 0 and b = 0


      is interpreted as



      (a = (0 and b)) = 0.


      But the and operator cannot accept an integer and a floating-point value as operands (two integers would have been OK, though). Hence the error.



      Had a and b been integers, 0 and b would have been the bitwise conjunction of 0 and b, that is, 0. Thus, we would have had



      (a = 0) = 0.


      This reads either true = 0 (if a is equal to 0) or false = 0 (if a is different from 0). But a boolean cannot be compared to an integer, so the compiler would have complained about that.



      Still, this was just an academic exercise. Clearly, your intension was



      (a = 0) and (b = 0).


      Just add the parentheses:



      if (b = 0) and (a = 0) then
      writeln('INFINITY')





      share|improve this answer


























        2












        2








        2







        At least in modern Delphi, and has higher precedence than =, so



        a = 0 and b = 0


        is interpreted as



        (a = (0 and b)) = 0.


        But the and operator cannot accept an integer and a floating-point value as operands (two integers would have been OK, though). Hence the error.



        Had a and b been integers, 0 and b would have been the bitwise conjunction of 0 and b, that is, 0. Thus, we would have had



        (a = 0) = 0.


        This reads either true = 0 (if a is equal to 0) or false = 0 (if a is different from 0). But a boolean cannot be compared to an integer, so the compiler would have complained about that.



        Still, this was just an academic exercise. Clearly, your intension was



        (a = 0) and (b = 0).


        Just add the parentheses:



        if (b = 0) and (a = 0) then
        writeln('INFINITY')





        share|improve this answer













        At least in modern Delphi, and has higher precedence than =, so



        a = 0 and b = 0


        is interpreted as



        (a = (0 and b)) = 0.


        But the and operator cannot accept an integer and a floating-point value as operands (two integers would have been OK, though). Hence the error.



        Had a and b been integers, 0 and b would have been the bitwise conjunction of 0 and b, that is, 0. Thus, we would have had



        (a = 0) = 0.


        This reads either true = 0 (if a is equal to 0) or false = 0 (if a is different from 0). But a boolean cannot be compared to an integer, so the compiler would have complained about that.



        Still, this was just an academic exercise. Clearly, your intension was



        (a = 0) and (b = 0).


        Just add the parentheses:



        if (b = 0) and (a = 0) then
        writeln('INFINITY')






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 11:31









        Andreas RejbrandAndreas Rejbrand

        72.4k6208302




        72.4k6208302






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445189%2flinear-equation-incompatible-types-boolean-longint%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Berounka

            Sphinx de Gizeh

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...