error handling when taking user input
<p>I am a beginner in c++ and I have a small problem:</p>

<p>my code displays a simple menu to the user providing three options:</p>

<pre><code>cout &lt;&lt; "\nQuadratic equation: a*X^2 + b*X + c = 0 main menu: "; 
cout &lt;&lt; "\n &lt;r&gt;  Give new coefficients"; 
cout &lt;&lt; "\n &lt;c&gt;  Calculate equations solutions"; 
cout &lt;&lt; "\n &lt;t&gt;  Terminate the program";
</code></pre>

<p>What I want is now is that, when a user enters:</p>

<ul>
<li>aer ->invalid input entered, try again </li>
<li>1 or any other number->invalid input entered, try again </li>
<li>rt ->invalid input entered,try again
(here the first character is correct but he entered 2 characters)</li>
<li>cf ->invalid input entered, try again</li>
</ul>

<p>ONLY IF THE USER ENTERS CORRECTLY ONE OF THE 3 SIMPLE CHARACTERS (r,c,t NONSENSITIVE CASE) to do sth. Otherwise a massage for invalid input should be printed and then the  main menu should appear again</p>

<p>I tried this but it doesnt work:</p>

<pre><code>char displayMainMenu()
{
char mainMenuChoice;
cout &lt;&lt; "\nQuadratic equation: a*X^2 + b*X + c = 0 main menu: "; 
cout &lt;&lt; "\n &lt;r&gt;  Give new coefficients"; 
cout &lt;&lt; "\n &lt;c&gt;  Calculate equations solutions"; 
cout &lt;&lt; "\n &lt;t&gt;  Terminate the program";
cout&lt;&lt;"Enter choice : ";
cin&gt;&gt;mainMenuChoice;
return mainMenuChoice;
}

int main()
{
bool done = false;
while(!done)
{
    char choice = displayMainMenu();  

    if( isalpha(choice) )
    {

     switch(tolower(choice))
     {
     case 'r':
      DoSTH1();
      break;
     case 'c':
      DoSTH2();
      break;  
     case 't':
      DoSTH3();                   
      break;
     default:
      cout&lt;&lt;"Invalid choice!\n"&lt;&lt;endl;
     }   

    }

}
return 0;
}
</code></pre>

<p>I hope u can help me</p>

<p>ADDED:
When i enter by mistake for example: cbbbbbb
it takes it as if it was 'c'</p>
