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.

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 modified 17.01.2025: new translations (f32b526)