title: How can I validate and convert an input to a single digit (int) in C++?
body: <p>I'm learning C++ and this is my code:</p>
  
  <pre><code>int val1,val2;
  char op;
  cout &lt;&lt; "Please enter a calculation (operand operator operand):";
  cin &gt;&gt; val1 &gt;&gt; op &gt;&gt; val2;
  if((val1&lt;0||val1&gt;9)||(val2&lt;0||val2&gt;9)) {
      cout &lt;&lt; "Operand must be between 0 and 10!" &lt;&lt; endl;
  }
  cout &lt;&lt; "val1: " &lt;&lt; val1 &lt;&lt; "  val2: " &lt;&lt; val2 &lt;&lt; endl;
  </code></pre>
  
  <p>The validation works but I still haven't just one digit in the variable val1 or val2 if I enter for example 34+56.  </p>
  
  <p>I want to end up with an error message for a number that has 2 digits or more and I want to have only one digit in the variables val1 and val2.  </p>
  
  <p>I tried working with chars, strings and isdigit() but I'm still in the dark here.  Thx for the help!!</p>