title: passing int variables in C++ - error check not returning value
body: <p>okay so I am trying to check variables when they are input by the user, however they don't seem to stick. now the error check seems to work, but the variable is lost somewhere leaving 'num = 0'</p>
  
  <p>I had copied some of this code from another source but I am not sure where it is going wrong.</p>
  
  <p>I would like to input a number, check if it is an integer, and then return said integer to the variable 'num'.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int checkCin(int var)       {//open function
  
  bool ok = false;//set variable to false
  while (!ok)/*if variable is false, loop*/               {//open loop 
  
      cin &gt;&gt; var;
  
      //this will cheack if anything is in variable other than an integer
      if(!cin.fail() &amp;&amp; (cin.peek()==EOF || cin.peek()=='\n'))        {//open if
          ok = true;//this will end loop
          return var;
  }//close if
  
      //this will clear the cin and ignor whats left - ignoring this part stops an infinate loop cycle 
  
      else        {//open else
          cin.clear();
          cin.ignore(256,'\n');
          cout &lt;&lt; "Error, enter a number" &lt;&lt; std::endl;
  
      }//close else
  }//close loop
  
  //prepared for next input
  ok = false;
  
  }//close function
  
  int main()    {
  
  int num = 0;
  
  checkCin(num);
  
  cout &lt;&lt; num &lt;&lt; endl;
  
  system("pause");
  return 0;
  }
  </code></pre>