Asks the user for a number, prints whether or not the number is greater than zero, using the if-else statement. - C++ Language Basics

C++ examples for Language Basics:Console

Description

Asks the user for a number, prints whether or not the number is greater than zero, using the if-else statement.

Demo Code

#include <iostream>
using namespace std;
int main()/*from ww w. ja  v a  2  s  . co  m*/
{
   int num;
   cout << "What is your number? ";
   cin >> num;   // Get the user's number.
   if (num > 0)
   {
      cout << "More than 0\n";
   }
   else
   {
      cout << "Less or equal to 0\n";
   }
   // No matter what the number was, the following executes.
   cout << "\n\nThanks for your time!\n";
   return 0;
}

Result


Related Tutorials