Has anyone got an even or odd number calculating program?

This is a discussion on Has anyone got an even or odd number calculating program? within the C++ Programming forums, part of the General Programming Boards category; If so, I would like to see the code....

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    367

    Has anyone got an even or odd number calculating program?

    If so, I would like to see the code.

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You show me yours and I'll show you mine.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    It's as simple as this:
    Code:
    if ( number % 2 )
      cout<<"Even"<<endl;
    else
      cout<<"Odd"<<endl;
    -Prelude
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    what do you mean "even or odd calculating program"?
    One that gives you a number and tells you if its even or odd?
    or one that only gives u even or odd random numbers?

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    >if ( number % 2 )
    does the % sign mean "Can be divided by"?
    (i am a bit newbie to C++ )

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    % tells you the remainder of a division operation. So if you divide by two and there's nothing left over then the number is even. You can perform the same calculation with the bitwise AND, but I won't get into that

    -Prelude
    My best code is written with the delete key.

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    ooooooooooooooo okay

  8. #8
    Registered User
    Join Date
    Dec 2001
    Posts
    367
    I mean a program that determines whetever a number is even or odd.

  9. #9
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Look up the modulus (%) operator.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Help C program that reads Odd numbers and evens
    By Cyberman86 in forum C Programming
    Replies: 4
    Last Post: 02-27-2009, 10:59 AM
  3. Replies: 6
    Last Post: 02-19-2009, 06:19 PM
  4. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  5. problem with my prime number program
    By datainjector in forum C Programming
    Replies: 4
    Last Post: 07-12-2002, 12:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21