468,497 Members | 1,813 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Easy True False Equation

29
Write the definition of a function isEven , which receives an integer parameter and returns true if the parameter's value is even, and false otherwise.

So if the parameter's value is 7 or 93 or 11 the function returns false. But if the parameter's value is 44 or 126 or 7778 the function returns true.
Oct 20 '06 #1
4 32439
arne
315 Expert 100+
Write the definition of a function isEven , which receives an integer parameter and returns true if the parameter's value is even, and false otherwise.

So if the parameter's value is 7 or 93 or 11 the function returns false. But if the parameter's value is 44 or 126 or 7778 the function returns true.
Hint: have a look at the modulo ( % ) operator ...
Oct 20 '06 #2
dru
29
I got this but I do now know hwo to return the answer true or false i know its 1 or 0

int isEven(int x);
{
if (x % 2 == 0){return 1;}
else {return 0;}
}
Oct 20 '06 #3
dru
29
the return is the only part I dont understand
Oct 20 '06 #4
arne
315 Expert 100+
the return is the only part I dont understand
Your code looks ok, just remove the ';' at the end of the first line!

Using true/false You could also code it like this
Expand|Select|Wrap|Line Numbers
  1. bool isEven(int x)
  2. {
  3.     if (x % 2 == 0) {
  4.         return true;
  5.     } else {
  6.                 return false;
  7.         }
  8. }
  9.  
Oct 21 '06 #5

Post your reply

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

Similar topics

4 posts views Thread by Pascal | last post: by
9 posts views Thread by Stud Muffin | last post: by
1 post views Thread by James Dean | last post: by
3 posts views Thread by mismis | last post: by
6 posts views Thread by Trev17 | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.