title: Stuck in an infinite loop when validating user input as an int
body: <p>So I'm displaying a menu using a do while loop as shown below, and I want the user to be prompted with the menu until they make a valid selection- by entering the digits 1, 2, 3 or 4. I then want to use a switch case statement for identifying the users choice and executing the relevant block of code. When it comes to input validation though, how can I account for the user entering a letter instead of a numerical digit? The below code successfully continues to the next iteration to reprompt the user when they enter a letter, except that it enters a continuous loop.</p>
  
  <pre><code>int selection;
  
  do{
      cout &lt;&lt; "Which option would you like to select? (select 1, 2, or 3)";
      cout &lt;&lt; "1: Option 1" &lt;&lt; endl;
      cout &lt;&lt; "2: Option 2" &lt;&lt; endl;
      cout &lt;&lt; "3: Option 2" &lt;&lt; endl;
  
      if(!(cin &gt;&gt; selection)){
          cout &lt;&lt; "Please select an integer from 1-4." &lt;&lt; endl;
          cin.clear()
      }
  
  }while(selection != (1) or (2) or (3) or (4));
  </code></pre>
  
  <p>I've tried inserting the code below using istringstream to stream the users response from a string into an int inside the while loop as an alternative method to try solving the problem but to no avail.    </p>
  
  <pre><code>string temp;
  cin &gt;&gt; temp;
  clearInputBuffer();
  istringstream is(temp);
  is &gt;&gt; selection;
  </code></pre>
  
  <hr>
  
  <p><strong>UPDATED CODE</strong>   - still getting an infinite loop (only when the user enters an alphabetic<br>
                                                         character; integers behaveas expected)</p>
  
  <pre><code>int selection;
  
  do{
      cout &lt;&lt; "Which option would you like to select? (select 1, 2, or 3)";
      cout &lt;&lt; "1: Option 1" &lt;&lt; endl;
      cout &lt;&lt; "2: Option 2" &lt;&lt; endl;
      cout &lt;&lt; "3: Option 2" &lt;&lt; endl;
  
      if(std::cin &gt;&gt; selection){
         cout &lt;&lt; "Enter the new price: ";
      }
  
      else if(!std::cin.eof()){
         cout &lt;&lt; "Please select an integer from 1-4." &lt;&lt; endl;
         cin.clear();
      }
  
  
      }while(selection != 1 &amp;&amp; selection != 2 &amp;&amp; selection != 3 &amp;&amp; selection != 4);
  </code></pre>