0

I am a newbie to c++.

  #include <iostream>
    using std::cout;
    using std::endl;
    using namespace std;
    int main()
    {
        int a = 0;
        int b = 10;
        cout << "Enter first number \n";
        cin >> a;
        if (a < 10)
        {
            cout << "Less";
        }
    }

now when i enter 5 nothing happens and console exits. i think it should display "Less" But it doesn't. Why?

designerNProgrammer
  • 2,621
  • 5
  • 34
  • 46

1 Answers1

2

It's because you are using some sort of IDE and usually in IDEs they display a console box that has your output, and that console box disappears when the program is done.

It is being shown, but the console window is exiting too fast for you to see it.

What you can do is add a few lines at the end, such as:

#include <iostream>
#include <string>
using std::cout;
using std::endl;
using namespace std;
int main()
{
    int a = 0;
    int b = 10;
    cout << "Enter first number \n";
    cin >> a;
    if (a < 10)
    {
        cout << "Less";
    }

    std::string pause;
    cin >> pause;
}