C++ How To Check if a Number Is Positive or Negative
Check if a Number Is Positive or Negative
Use if, else if and else to check if a number is positive, negative or zero:
Example
int number = -5;
if (number > 0) {
cout << "Positive";
} else if (number < 0) {
cout << "Negative";
} else {
cout << "Zero";
}
Explanation:
A number larger than 0 is positive, and a number smaller than 0 is negative.
If it is neither, it must be 0.