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

User Art Doler
by
3.0k points

1 Answer

17 votes
17 votes

Answer:

// header files

#include <iostream>

using namespace std;

// required function

bool isPositive(int num)

{

// check if number is positive

if (num > 0)

{

// return true

return true;

}

// if number is 0 or negative

else

{

// retrun false

return false ;

}

}

// main function

int main() {

// test the function with different values

cout<<isPositive(7)<<endl;

cout<<isPositive(803)<<endl;

cout<<isPositive(141)<<endl;

cout<<isPositive(-22)<<endl;

cout<<isPositive(-57)<<endl;

cout<<isPositive(0)<<endl;

return 0;

}

User Brownie
by
2.9k points