Finding whether a number is positive or negative with C++
Finding whether a number is positive or negative with C++
In this example, we check whether the number entered from the keyboard is positive, negative or zero by using if-else if.
#include <iostream>
using namespace std;
int main() {
int number;
cout << "Please enter a number: ";
cin >> number;
if (number > 0) {
cout << "Number is positive";
} else if (number < 0) {
cout << "Number is negative";
} else {
cout << "Number is zero";
}
return 0;
}
Last updated on