Using MOD in Pascal










-1















I'm just starting coding and programming and white trying to complete an exercise I noted that the MOD operation doesn't work with variables.
Can someone explain to me why? And also give me some tips on how to do it? Thank you.



program Stack_Overflow;
var
sec, hour, day: real;


begin

WriteLn('Insert a number of seconds.');
ReadLn (sec);


hour := sec div 3600;
writeln (hour);

readln;
end.









share|improve this question



















  • 1





    Please add an expample to help us to help you

    – Nifriz
    Nov 12 '18 at 16:59







  • 3





    MOD certainly does work with variables. Could you show us your code?

    – David Dubois
    Nov 12 '18 at 16:59











  • I'm not level 10 in reputation so i can't post photos.

    – Sebastião Assunção
    Nov 12 '18 at 17:04











  • But basically I asked the user to provide a number of seconds and then i did hours:= sec mod 600. And it didn't work

    – Sebastião Assunção
    Nov 12 '18 at 17:05







  • 2





    It's good that you can't post photos, because we want the code as text, not as a screenshot. Please post a Minimal, Complete, and Verifiable example and the error message that you get when you try to run the code.

    – JJJ
    Nov 12 '18 at 17:12















-1















I'm just starting coding and programming and white trying to complete an exercise I noted that the MOD operation doesn't work with variables.
Can someone explain to me why? And also give me some tips on how to do it? Thank you.



program Stack_Overflow;
var
sec, hour, day: real;


begin

WriteLn('Insert a number of seconds.');
ReadLn (sec);


hour := sec div 3600;
writeln (hour);

readln;
end.









share|improve this question



















  • 1





    Please add an expample to help us to help you

    – Nifriz
    Nov 12 '18 at 16:59







  • 3





    MOD certainly does work with variables. Could you show us your code?

    – David Dubois
    Nov 12 '18 at 16:59











  • I'm not level 10 in reputation so i can't post photos.

    – Sebastião Assunção
    Nov 12 '18 at 17:04











  • But basically I asked the user to provide a number of seconds and then i did hours:= sec mod 600. And it didn't work

    – Sebastião Assunção
    Nov 12 '18 at 17:05







  • 2





    It's good that you can't post photos, because we want the code as text, not as a screenshot. Please post a Minimal, Complete, and Verifiable example and the error message that you get when you try to run the code.

    – JJJ
    Nov 12 '18 at 17:12













-1












-1








-1








I'm just starting coding and programming and white trying to complete an exercise I noted that the MOD operation doesn't work with variables.
Can someone explain to me why? And also give me some tips on how to do it? Thank you.



program Stack_Overflow;
var
sec, hour, day: real;


begin

WriteLn('Insert a number of seconds.');
ReadLn (sec);


hour := sec div 3600;
writeln (hour);

readln;
end.









share|improve this question
















I'm just starting coding and programming and white trying to complete an exercise I noted that the MOD operation doesn't work with variables.
Can someone explain to me why? And also give me some tips on how to do it? Thank you.



program Stack_Overflow;
var
sec, hour, day: real;


begin

WriteLn('Insert a number of seconds.');
ReadLn (sec);


hour := sec div 3600;
writeln (hour);

readln;
end.






pascal






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 17:35









MartynA

20.2k32154




20.2k32154










asked Nov 12 '18 at 16:56









Sebastião AssunçãoSebastião Assunção

12




12







  • 1





    Please add an expample to help us to help you

    – Nifriz
    Nov 12 '18 at 16:59







  • 3





    MOD certainly does work with variables. Could you show us your code?

    – David Dubois
    Nov 12 '18 at 16:59











  • I'm not level 10 in reputation so i can't post photos.

    – Sebastião Assunção
    Nov 12 '18 at 17:04











  • But basically I asked the user to provide a number of seconds and then i did hours:= sec mod 600. And it didn't work

    – Sebastião Assunção
    Nov 12 '18 at 17:05







  • 2





    It's good that you can't post photos, because we want the code as text, not as a screenshot. Please post a Minimal, Complete, and Verifiable example and the error message that you get when you try to run the code.

    – JJJ
    Nov 12 '18 at 17:12












  • 1





    Please add an expample to help us to help you

    – Nifriz
    Nov 12 '18 at 16:59







  • 3





    MOD certainly does work with variables. Could you show us your code?

    – David Dubois
    Nov 12 '18 at 16:59











  • I'm not level 10 in reputation so i can't post photos.

    – Sebastião Assunção
    Nov 12 '18 at 17:04











  • But basically I asked the user to provide a number of seconds and then i did hours:= sec mod 600. And it didn't work

    – Sebastião Assunção
    Nov 12 '18 at 17:05







  • 2





    It's good that you can't post photos, because we want the code as text, not as a screenshot. Please post a Minimal, Complete, and Verifiable example and the error message that you get when you try to run the code.

    – JJJ
    Nov 12 '18 at 17:12







1




1





Please add an expample to help us to help you

– Nifriz
Nov 12 '18 at 16:59






Please add an expample to help us to help you

– Nifriz
Nov 12 '18 at 16:59





3




3





MOD certainly does work with variables. Could you show us your code?

– David Dubois
Nov 12 '18 at 16:59





MOD certainly does work with variables. Could you show us your code?

– David Dubois
Nov 12 '18 at 16:59













I'm not level 10 in reputation so i can't post photos.

– Sebastião Assunção
Nov 12 '18 at 17:04





I'm not level 10 in reputation so i can't post photos.

– Sebastião Assunção
Nov 12 '18 at 17:04













But basically I asked the user to provide a number of seconds and then i did hours:= sec mod 600. And it didn't work

– Sebastião Assunção
Nov 12 '18 at 17:05






But basically I asked the user to provide a number of seconds and then i did hours:= sec mod 600. And it didn't work

– Sebastião Assunção
Nov 12 '18 at 17:05





2




2





It's good that you can't post photos, because we want the code as text, not as a screenshot. Please post a Minimal, Complete, and Verifiable example and the error message that you get when you try to run the code.

– JJJ
Nov 12 '18 at 17:12





It's good that you can't post photos, because we want the code as text, not as a screenshot. Please post a Minimal, Complete, and Verifiable example and the error message that you get when you try to run the code.

– JJJ
Nov 12 '18 at 17:12












2 Answers
2






active

oldest

votes


















2














DIV and MOD operators works only on integers, not on floating point numbers.



Just declare:



var
sec, hour, day: integer;


and you are good to go.






share|improve this answer























  • Well yes, as far as one can go with ZIM. <g> +1.

    – Rudy Velthuis
    Nov 12 '18 at 18:13











  • @RudyVelthuis, can't be worse than punching cards for the univac, where I started learning programming.

    – LU RD
    Nov 12 '18 at 18:29











  • You had cards? Luxury! We had to wire the hardware directly. etc...

    – Rudy Velthuis
    Nov 13 '18 at 1:05


















0














MOD is well defined for integers only but there are not meant for real. MOD gives you the remainder of integer division a / b , but real division doesn't have remainders.Instead if you want to find the remainder of a real number you can create your own MOD fuction.



//You can either code it as a fuction so its reusability.



Remainder:=Trunc(sec/3600) ; truncate removes the decimal part ang gives you the integer part.This like MOD.






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%2f53266777%2fusing-mod-in-pascal%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    DIV and MOD operators works only on integers, not on floating point numbers.



    Just declare:



    var
    sec, hour, day: integer;


    and you are good to go.






    share|improve this answer























    • Well yes, as far as one can go with ZIM. <g> +1.

      – Rudy Velthuis
      Nov 12 '18 at 18:13











    • @RudyVelthuis, can't be worse than punching cards for the univac, where I started learning programming.

      – LU RD
      Nov 12 '18 at 18:29











    • You had cards? Luxury! We had to wire the hardware directly. etc...

      – Rudy Velthuis
      Nov 13 '18 at 1:05















    2














    DIV and MOD operators works only on integers, not on floating point numbers.



    Just declare:



    var
    sec, hour, day: integer;


    and you are good to go.






    share|improve this answer























    • Well yes, as far as one can go with ZIM. <g> +1.

      – Rudy Velthuis
      Nov 12 '18 at 18:13











    • @RudyVelthuis, can't be worse than punching cards for the univac, where I started learning programming.

      – LU RD
      Nov 12 '18 at 18:29











    • You had cards? Luxury! We had to wire the hardware directly. etc...

      – Rudy Velthuis
      Nov 13 '18 at 1:05













    2












    2








    2







    DIV and MOD operators works only on integers, not on floating point numbers.



    Just declare:



    var
    sec, hour, day: integer;


    and you are good to go.






    share|improve this answer













    DIV and MOD operators works only on integers, not on floating point numbers.



    Just declare:



    var
    sec, hour, day: integer;


    and you are good to go.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 12 '18 at 18:12









    LU RDLU RD

    28.3k559179




    28.3k559179












    • Well yes, as far as one can go with ZIM. <g> +1.

      – Rudy Velthuis
      Nov 12 '18 at 18:13











    • @RudyVelthuis, can't be worse than punching cards for the univac, where I started learning programming.

      – LU RD
      Nov 12 '18 at 18:29











    • You had cards? Luxury! We had to wire the hardware directly. etc...

      – Rudy Velthuis
      Nov 13 '18 at 1:05

















    • Well yes, as far as one can go with ZIM. <g> +1.

      – Rudy Velthuis
      Nov 12 '18 at 18:13











    • @RudyVelthuis, can't be worse than punching cards for the univac, where I started learning programming.

      – LU RD
      Nov 12 '18 at 18:29











    • You had cards? Luxury! We had to wire the hardware directly. etc...

      – Rudy Velthuis
      Nov 13 '18 at 1:05
















    Well yes, as far as one can go with ZIM. <g> +1.

    – Rudy Velthuis
    Nov 12 '18 at 18:13





    Well yes, as far as one can go with ZIM. <g> +1.

    – Rudy Velthuis
    Nov 12 '18 at 18:13













    @RudyVelthuis, can't be worse than punching cards for the univac, where I started learning programming.

    – LU RD
    Nov 12 '18 at 18:29





    @RudyVelthuis, can't be worse than punching cards for the univac, where I started learning programming.

    – LU RD
    Nov 12 '18 at 18:29













    You had cards? Luxury! We had to wire the hardware directly. etc...

    – Rudy Velthuis
    Nov 13 '18 at 1:05





    You had cards? Luxury! We had to wire the hardware directly. etc...

    – Rudy Velthuis
    Nov 13 '18 at 1:05













    0














    MOD is well defined for integers only but there are not meant for real. MOD gives you the remainder of integer division a / b , but real division doesn't have remainders.Instead if you want to find the remainder of a real number you can create your own MOD fuction.



    //You can either code it as a fuction so its reusability.



    Remainder:=Trunc(sec/3600) ; truncate removes the decimal part ang gives you the integer part.This like MOD.






    share|improve this answer



























      0














      MOD is well defined for integers only but there are not meant for real. MOD gives you the remainder of integer division a / b , but real division doesn't have remainders.Instead if you want to find the remainder of a real number you can create your own MOD fuction.



      //You can either code it as a fuction so its reusability.



      Remainder:=Trunc(sec/3600) ; truncate removes the decimal part ang gives you the integer part.This like MOD.






      share|improve this answer

























        0












        0








        0







        MOD is well defined for integers only but there are not meant for real. MOD gives you the remainder of integer division a / b , but real division doesn't have remainders.Instead if you want to find the remainder of a real number you can create your own MOD fuction.



        //You can either code it as a fuction so its reusability.



        Remainder:=Trunc(sec/3600) ; truncate removes the decimal part ang gives you the integer part.This like MOD.






        share|improve this answer













        MOD is well defined for integers only but there are not meant for real. MOD gives you the remainder of integer division a / b , but real division doesn't have remainders.Instead if you want to find the remainder of a real number you can create your own MOD fuction.



        //You can either code it as a fuction so its reusability.



        Remainder:=Trunc(sec/3600) ; truncate removes the decimal part ang gives you the integer part.This like MOD.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 0:37









        lasal22lasal22

        11




        11



























            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%2f53266777%2fusing-mod-in-pascal%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

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo