469,936 Members | 2,413 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,936 developers. It's quick & easy.

Telling the Difference between Even and Odd numbers

sonic
40
During input validation, how would one decipher between even and odd numbers? I have to write a program that allows an individual to select numbers between 2-14, excluding odds. Here is a snippet from that code line:

if (usersel < 2 || usersel >14)
cout << "Invalid input. Please try again.";


What would I place in the third or comparison to weed out the odd numbers?
Thank you for taking the time to read this.
Nov 7 '06 #1
1 8947
Hi,

Use modulus operator, %. It computes the remainer that results from performing integer division.

if(number % 2 == 0) => number is even
else number is odd.

~David
Nov 7 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Sonia | last post: by
4 posts views Thread by ravinderthakur | last post: by
26 posts views Thread by Michel Rouzic | last post: by
47 posts views Thread by mwql | last post: by
30 posts views Thread by bdsatish | last post: by
11 posts views Thread by cmb3587 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.