title: How to make an exit in switch case implementation with user prompt?
body: <p>I've a basic computing program, in it I want that when a user wants to just quit the program in his very first input without making any calculation, the program just exits. But rather here if the user enters <code>q for quit/exit</code> in his first input the programs runs into an infinite loop. Is there any way to provide user with some single exit key which when entered anytime(by the user) during runtime just quits the program. The innermost while loop works fine unless the outermost loop stops working.</p>
  
  <pre><code>#include "std_lib_facilities.h"
  int main() {
      double x = 0, y = 0, result = 0;
      string operation = " ";
      char op = ' ';
      cout &lt;&lt; "\nInput (e.g. -&gt; 5*6)\nPress q to quit.\n";
      while(1) {
          cin &gt;&gt; x &gt;&gt; op &gt;&gt; y;
          switch(op) {
          case '+':
              result = x + y;
              operation = "sum";
              break;
          //Other switch cases
          case 'q':
              exit(1);
          default:
              cout &lt;&lt; "Invalid input.";
              break;
          }
          cout &lt;&lt; "The " &lt;&lt; operation &lt;&lt; " of " &lt;&lt; x &lt;&lt; " and " &lt;&lt; y &lt;&lt; " is "
              &lt;&lt; result &lt;&lt; ".\n\n"
              &lt;&lt; "If you have another input, press any character to continue..\n"
              &lt;&lt; "Else press q to quit.\n";
          // exit or continue program loop
          while(cin &gt;&gt; op) {
              if(op=='q' || op=='Q')
                  exit(1);
              else
                  cout &lt;&lt; "Provide next set of inputs.\n";
              break;
          }
      }
  }
  </code></pre>