title: How can I accept user input differently from the same line in C++?
body: <p>I have an assignment for my intro C++ class to make a program that has a user select C, D, or E to process a check, deposit a check, or end the program respectively. The professor specified that if a user chooses C or D, he would like to accept both the selection and the amount of money in the same line. For example, if a user wants to deposit a check for $20, they would enter "D 20" in one line. I have it set up as such:</p>
  
  <pre><code>cout &lt;&lt; "Enter the beginning balance:\n\n";
  cin &gt;&gt; balance;
  
  cout &lt;&lt; "Commands:\n";
  cout &lt;&lt; "C - process a check\n";
  cout &lt;&lt; "D - process a deposit\n";
  cout &lt;&lt; "E - end the program\n\n";
  
  while (choice != 'E')
  {
      cout &lt;&lt; "Enter a transaction:\n";
      cin &gt;&gt; choice &gt;&gt; amount;
  </code></pre>
  
  <p>Followed by a switch statement. The code itself works properly when entering C or D, but when I go to enter E to end the program, it will only work if I add a number to the end, because the line asking for input wants a char and a float. However, in the example output my professor showed, you could just enter E and it would terminate. Is there any way around this? How can I set it up so it accepts E differently from C and D?</p>
  
  <p>EDIT: Here is the switch statement:</p>
  
  <pre><code>switch(choice)
  {
      case 'C':cout &lt;&lt; fixed &lt;&lt; setprecision(2);
               cout &lt;&lt; "Processing check for $" &lt;&lt; amount &lt;&lt; endl;
               balance = processCheck(amount, balance);
               cout &lt;&lt; "Balance: $" &lt;&lt; balance &lt;&lt; endl;
               break;
      case 'D':cout &lt;&lt; fixed &lt;&lt; setprecision(2);
               cout &lt;&lt; "Processing deposit for $" &lt;&lt; amount &lt;&lt; endl;
               balance = depositCheck(amount, balance);
               cout &lt;&lt; "Balance: $" &lt;&lt; balance &lt;&lt; endl;
               break;
      case 'E':cout &lt;&lt; "Processing end of month\n";
               cout &lt;&lt; "Final balance: $" &lt;&lt; balance &lt;&lt; endl;
               break;
      default : cout &lt;&lt; "Invalid choice\n";
  }
  </code></pre>