title: How to allow only positive integer input from user?
body: <p>I have been trying to <strong>only allow positive integer input</strong> into my program. But works it is getting past with the <em>character</em> input and <em>negative integers</em>, <em>decimal numbers</em>. Any ideas how to fix that?</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
      int row, col, i, i1, j, test;
      double n;
      test = 0;
  
      while (test == 0) 
      {
          cout &lt;&lt; "Enter the number of rows: " &lt;&lt; endl;
          cin &gt;&gt; row;
          if (cin.fail() || row &lt;= 0 || !(row == (int)row)) 
          {
              cout &lt;&lt; "\nEntered value is wrong!";
              printf("\n");
              cin.clear();
              cin.ignore();
              test = 0;
          }
          else {  test = 1;  }
      }
  }
  </code></pre>