title: How to check for integer range?
body: <p>I have this code, but it prints garbage when I enter a value which exceeds integer value. I have actually if condition to check for the range. How to make it work? I know this is easy for you. I just forgot some things in C++ and I have no time.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;typeinfo&gt;
  #include&lt;cfloat&gt;
  #include&lt;climits&gt;
  
  using namespace std;
  
  int    g1, g2;
  string text  = " year";
  string text2 = " age";
  
  int main() {
    g1 = 2100000000000000000000000;
    g2 = 16;
  
    if (g1 &lt; INT_MIN || g1 &gt; INT_MAX) {
      std::cout &lt;&lt; "Please enter an integer";
    } else {
      std::cout &lt;&lt; g1 &lt;&lt; text;
      std::cout &lt;&lt; g2 &lt;&lt; text2;
    }
  
    return 0;
  }
  </code></pre>