title: Limiting user input
body: <p>I have written the following code and to a large extent it does what I want it to do.  The issue is that when the user can enter something like "111" and the output is "You entered the number 1."  I want to limit the user's input to 1 character.  Any suggestions?  I'm sure the solution is quite simple, but I can't figure it out.  Also, the code must remain in the form of a switch statement.  Thank you!</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
      char i;
  
      cout &lt;&lt; "Please enter a number between 1 and 9." &lt;&lt; endl;
      cout &lt;&lt; "Enter a number: ";
      cin &gt;&gt; i;
  
      switch (i)
          {
          case '1':
              cout &lt;&lt; "You entered the number one." &lt;&lt; endl;
              break;
  
          case '2':
              cout &lt;&lt; "You entered the number two." &lt;&lt; endl;
              break;
  
          case '3':
              cout &lt;&lt; "You entered the number three." &lt;&lt; endl;
              break;
  
          case '4':
              cout &lt;&lt; "You entered the number four." &lt;&lt; endl;
              break;
  
          case '5':
              cout &lt;&lt; "You entered the number five." &lt;&lt; endl;
              break;
  
          case '6':
              cout &lt;&lt; "You entered the number six." &lt;&lt; endl;
              break;
  
          case '7':
              cout &lt;&lt; "You entered the number seven." &lt;&lt; endl;
              break;
  
          case '8':
              cout &lt;&lt; "You entered the number eight." &lt;&lt; endl;
              break;
  
          case '9':
              cout &lt;&lt; "You entered the number nine." &lt;&lt; endl;
              break;
  
          default:
              cout &lt;&lt; "You did not enter a valid number." &lt;&lt; endl;
              break;
          }
  
      system("pause");
      return 0;
  }
  </code></pre>