Thread: Mistake in the site's FAQ

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    46

    Mistake in the site's FAQ

    The faq concerning determining if an integer is even or odd.The code written is wrong and i've tested it too.http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    I think if's should have the NOT operator.Please check to see if I'm wrong and how should I report it?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It returns the remainder of number divided by 2. If there is no remainder, it's an even number, and will return zero. If there is a remainder, it will return 1.

    It depends on how you want it to work really. If you're expecting it to work like strcmp, which returns 0 on "true", it won't work how you expect. However, if you look at it as logical true / false works, anything non-zero is true, so it's "correct".


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    46
    but i tried compiling the code and the program gave me the oppposite results.try it yourself.then try adding not to the if's

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I have tried it myself. It works fine, and there is no need to edit it. Try copying and pasting the code in. I get "Yep..." and "Nope..." respectively.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    46
    well its supposed to be no then yes cuz first i is 21 then i is 26
    Last edited by KidMan; 08-23-2006 at 08:12 PM.

  6. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    You're correct it's backwards. It returns 0 if it's even, in otherwords, false, yet the result of the condition prints that it's true. You can email or PM webmaster and he'll fix it.
    Sent from my iPadŽ

  7. #7
    Registered User
    Join Date
    Sep 2005
    Posts
    46
    Thank you for the second time 2day SlyMaelstrom

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You're right. I'll use the excuse that I was on the phone at the time, because no one can prove otherwise! HAH!

    I was thinking it was checking for if it was odd or not. They should probably fix it by doing:
    Code:
    int IsEven(int i)
    {
      return (i % 2 == 0 );
    }
    At least someone's awake around here. Good catch.


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Registered User
    Join Date
    Sep 2005
    Posts
    46
    So how should I report this mistake?

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Spam it on all of the forums until you get banned for spamming. At least it'll get noticed.
    Actually there is a sticky on how to get a thread moved to the FAQ board. That's probably close enough. If not, someone will be along shortly that will probably see it.


    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    A clever way to do this is to AND with 1.

  12. #12
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by KidMan
    So how should I report this mistake?
    I think you just did. The timeliness of any correction may be in question.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  13. #13
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by Yasir_Malik
    A clever way to do this is to AND with 1.
    By clever do you mean absurdly unnecessary?
    Sent from my iPadŽ

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Yasir_Malik
    A clever way to do this is to AND with 1.
    I believe there's actually a thread around some place saying why this isn't portable. A quick visit to Scroogle, a glance at the second link, gives us all we need to know.


    Quzah.
    Hope is the first step on the road to disappointment.

  15. #15
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by SlyMaelstrom
    By clever do you mean absurdly unnecessary?
    Well, if it was portable, it would in theory be faster than the modulus version. Bitwise operators tend to be faster than division and modulus. That's why people used to use shifting for division by two instead of the division operator.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wiki FAQ
    By dwks in forum A Brief History of Cprogramming.com
    Replies: 192
    Last Post: 04-29-2008, 01:17 PM
  2. Shareware Sites - Updating Them
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 11-11-2002, 02:58 AM
  3. FAQ Check/Lock
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-15-2002, 11:21 AM