6.9: Returning a Boolean Value

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Write the definition of a function isEven, that 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 .

bool isEven(int x){ if (x%2 == 0){ return true; } else { return false; } }

Write the definition of a function isPositive, that receives an integer parameter and returns true if the parameter is positive, and false otherwise. So, if the parameter 's value is 7 or 803 or 141 the function returns true . But if the parameter 's value is -22 or -57, or 0, the function returns false .

bool isPositive(int x){ if (x > 0) { return true; } else { return false; } }

Write the definition of a function isSenior, that receives an integer parameter and returns true if the parameter 's value is greater or equal to 65, and false otherwise. So, if the parameter 's value is 7 or 64 or 12 the function returns false . But if the parameter 's value is 69 or 83 or 65 the function returns true .

bool isSenior(int x ){ if (x >=65){ return true; } else{ return false; } }


Kaugnay na mga set ng pag-aaral

IO psych: Chapter 7-Performance apprasial

View Set

Math - 3.12 Quiz: Use Slope as a Rate

View Set

Chapter 23: Legal Implications in Nursing Practice (Legal Implications in Nursing)

View Set

Survey of Environmental Health - Final Exam Questions

View Set

EXAM 2 LEADERSHIP STUDY GUIDE from Test 1

View Set