title: C++ Maths in Switch statements
body: <p>So I am looking to do a simple maths equation that prints a menu and then takes in the Operator as a <code>char</code>. Then, it prompts the user into entering two numbers and then prints the resulting question and then answer in a format such as: <code>10 + 20 = 30</code>. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdio&gt;
  
  using namespace std;
  
  int main()
  {
      //Variables
      char op_choice;
      int usrnum_1;
      int usrnum_2;
  
      //Menu
      cout &lt;&lt; "Operator Menu\n\n";
      cout &lt;&lt; "+\n";
      cout &lt;&lt; "-\n";
      cout &lt;&lt; "*\n";
      cout &lt;&lt; "/\n";
      cout &lt;&lt; "%\n\n";
  
      cout &lt;&lt; "Choice:";
      cin &gt;&gt; op_choice;
      cout &lt;&lt; "\nNumbers:";
      cout &lt;&lt; "\n\nEnter TWO numbers to complete an arithmitic operation with the " &lt;&lt; op_choice &lt;&lt; " operator: \n";
      cout &lt;&lt; "eg: 1 + 2 = 3\n";
      cout &lt;&lt; "\nNumber 1: ";
      cin &gt;&gt; usrnum_1;
      cout &lt;&lt; "Number 2: ";
      cin &gt;&gt; usrnum_2;
  
      switch (op_choice)
      {
          case '+':
              break;
          case '-':
              cout &lt;&lt; "\nYou picked " &lt;&lt; usrnum_1 &lt;&lt; " - " &lt;&lt; usrnum_2 &lt;&lt; " = ";
              cout &lt;&lt; usrnum_1 - usrnum_2;
              break;
          case '*':
              cout &lt;&lt; "\nYou picked " &lt;&lt; usrnum_1 &lt;&lt; " X " &lt;&lt; usrnum_2 &lt;&lt; " = ";
              cout &lt;&lt; usrnum_1 * usrnum_2;
              break;
          case '/':
              cout &lt;&lt; "\nYou picked " &lt;&lt; usrnum_1 &lt;&lt; " / " &lt;&lt; usrnum_2 &lt;&lt; " = ";
              cout &lt;&lt; usrnum_1 / usrnum_2;
              break;
          case '%':
              cout &lt;&lt; "\nYou picked " &lt;&lt; usrnum_1 &lt;&lt; " % " &lt;&lt; usrnum_2 &lt;&lt; " = ";
              cout &lt;&lt; usrnum_1 % usrnum_2;
              break;
          default:
              cout &lt;&lt; "\nYou made an illegal choice.\n";
      }
  
      cout &lt;&lt; "\nYou picked " &lt;&lt; usrnum_1 &lt;&lt; " " &lt;&lt;  op_choice &lt;&lt; " " &lt;&lt;  usrnum_2 &lt;&lt; " = ";
      cout &lt;&lt; usrnum_1 &lt;&lt; op_choice &lt;&lt; usrnum_2;
  
      getchar();
      return 0;
  }
  </code></pre>
  
  <p>I have actually got this code working as you can see from the subtraction and multiplication etc. But I'm looking to get the cout outside the switch block (which I started doing and was testing with add). Is there a way to make this work without making op_choice into an int originally? Or putting the cout statement into the switch block? Would it be better to use an  if-else-if statement?</p>