title: C++ How to enter user values without breaking program
body: <p>I am trying to get an integer from the user but if they type "ckefkfek" it will cause the program to spam and break. I also want them to enter a float but I get the same problem and no clue how to check for this.</p>
  
  <pre><code>int option = 0;
  while (option != 3)
  {
      cout &lt;&lt; "Enter 1, 2, or 3: ";
      cin &gt;&gt; option;
      switch (option)
      {
          case 1:
              cout &lt;&lt; "Enter a float: ";
              float myfloat;
              cin &gt;&gt; myfloat;
              myFunc(myfloat); // must be a float for this function to work.
              break;
          case 2:
              // do stuff
              break;
          case 3:
              // do stuff
              break;
          default:
              cout &lt;&lt; endl &lt;&lt; "Not a valid option." &lt;&lt; endl;
              break;
      }
  }
  </code></pre>
  
  <p>How can I do this without constant errors? Thank you!</p>