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.
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.
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.
I can’t believe he needs that much code for this:
bool iseven(int number){ if (number % 2 == 0){ return true; } else { return false; } }
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?
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?
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.
Readability over obscure hacks
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.
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.
Hey now, this is a serious academic conversation about the 2 percent operator.
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.
Sorry I should’ve put the /s. I was just playing. But thank you for the helpful explanation, nonetheless. You are a nice person.
Whooosh
Whoosh