error-handling-when-taking-user-input part2
<p>I made previously a question:
<a href="http://stackoverflow.com/questions/236354/error-handling-when-taking-user-input">http://stackoverflow.com/questions/236354/error-handling-when-taking-user-input</a></p>

<p>and I made the suggested changes:</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();  
    switch(tolower(choice))
    {
        case 'r':
                cout&lt;&lt;"Entered case 'r'";
                break;
        case 'c':
                cout&lt;&lt;"Entered case 'c'";
                break;  
        case 't':
                cout&lt;&lt;"Entered case 't'";                   
                break;
        default:
                cout&lt;&lt;"Invalid choice! Try again"&lt;&lt;endl;   
    }
}
return 0;
}
</code></pre>

<p>The new problem is that if the user enters by mistake lets say "ter" i get the following :( :</p>

<pre><code>Quadratic equation: a*X^2 + b*X + c = 0 main menu:   
 &lt;r&gt;  Give new coefficients 
 &lt;c&gt;  Calculate equations solutions  
 &lt;t&gt;  Terminate the program 
Enter choice : ter 
Entered case 't'

Quadratic equation: a*X^2 + b*X + c = 0 main menu:  
 &lt;r&gt;  Give new coefficients 
 &lt;c&gt;  Calculate equations solutions  
 &lt;t&gt;  Terminate the program 
Enter choice : Invalid choice! Try again

Quadratic equation: a*X^2 + b*X + c = 0 main menu:  
 &lt;r&gt;  Give new coefficients 
 &lt;c&gt;  Calculate equations solutions  
 &lt;t&gt;  Terminate the program 
Enter choice : Invalid choice! Try again
</code></pre>

<p>How could I avoid this from happening??</p>
