Easy True False Equation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dru
    New Member
    • Sep 2006
    • 29

    Easy True False Equation

    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.
  • arne
    Recognized Expert Contributor
    • Oct 2006
    • 315

    #2
    Originally posted by dru
    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 ...

    Comment

    • dru
      New Member
      • Sep 2006
      • 29

      #3
      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;}
      }

      Comment

      • dru
        New Member
        • Sep 2006
        • 29

        #4
        the return is the only part I dont understand

        Comment

        • arne
          Recognized Expert Contributor
          • Oct 2006
          • 315

          #5
          Originally posted by dru
          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
          Code:
          bool isEven(int x)
          {
          	if (x % 2 == 0) {
          		return true;
          	} else {
                          return false;
                  }
          }

          Comment

          Working...