• wtry@lemm.ee
    link
    fedilink
    arrow-up
    10
    arrow-down
    3
    ·
    edit-2
    1 year ago

    I can’t believe he needs that much code for this: bool iseven(int number){ if (number % 2 == 0){ return true; } else { return false; } }

    • TopRamenBinLaden@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      18
      ·
      1 year ago

      I like the example in the post better. It is more clear as to what is going on to an experienced dev like me. What’s this 2 percent nonsense?

      • Clearwatermo@lemmy.world
        link
        fedilink
        arrow-up
        5
        ·
        1 year ago

        I like the example in the comment better. It is more confusing as to what is going on to an experienced dev like me. iSeven is always odd tho right?

        • TopRamenBinLaden@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 year ago

          I think you are on to something there. Personally, I just don’t see the advantage of using iSeven over iSix, though. I might start using iEight whenever they finally iron the kinks out of that one.

        • rustbuckett@lemmings.world
          link
          fedilink
          arrow-up
          4
          arrow-down
          1
          ·
          1 year ago

          It’s not obscure. This is the example, with syntactic differences, for this problem in almost every programming book I’ve read. He just didn’t include newlines.

          • mob@lemmy.world
            link
            fedilink
            arrow-up
            8
            ·
            1 year ago

            At this point, I really can’t tell who’s joking around or who’s being serious in this thread.

            Shits cracking me up though reading this all as serious discussion.

      • EvokerKing@lemmy.world
        link
        fedilink
        arrow-up
        7
        arrow-down
        3
        ·
        1 year ago

        Explanation: the percent is modulus. Basically it’s just divide the first number by the second and return the remainder. If you do number % 2, it will return 1 if it is odd and 0 if it is even. For example 4/2 has a remainder of 0 and therefore is even. 3/2 has a remainder of 1, and therefore is odd.

        • TopRamenBinLaden@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          4
          ·
          edit-2
          1 year ago

          Sorry I should’ve put the /s. I was just playing. But thank you for the helpful explanation, nonetheless. You are a nice person.