C++ Check if the number is Positive or Negative Program
In this tutorial, we will learn how to determine if the entered number is Positive or Negative, in the C++ programming language.
This can be done by the concept of
if-else blocks in C++ (Learn C++ if-else).
The below given commented code will help you understand this concept in detail.
using namespace std;
cout << "\n\nWelcome to Studytonight :-)\n\n\n";
cout << " ===== Program to Check if the number is positive or negative ===== \n\n";
//taking user input
cout << "Enter any non-zero Number to be checked: ";
cin >> num;
//when the condition inside the if() is true, then it enters the code block
if (num > 0)
cout << "\nEntered number is positive";
else //when if is not executed then it moves to the else block
cout << "\nEntered number is negative";
cout << "\n\n\n";
We hope that this post helped you develop a better understanding of the logic of
if else blocks, in C++. For any query, feel free to reach out to us via the comments section down below.
Keep Learning : )