title: C++ switch statement for arithmetic operations
body: <p>When I run my program, it doesn't allow me to pick an operation.  It just goes straight to "Invalid option" and asks again.  I want to be able to choose '+', '-', '*', '/', '^', and '!' as my options. What did I do wrong?  </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;fstream&gt;
  #include &lt;cstdlib&gt;
  
  using namespace std;
  
  int main()
  {
  
  char operation;
  int num1, num2, result, remain;
  
  //Display the menu to the user and get their first choice
  
      cout &lt;&lt; "What operation would you like to perform:" &lt;&lt; endl 
      &lt;&lt; " + addition\n - subtraction\n * multiplication\n / division\n ^ number to power\n ! factorial" 
      &lt;&lt; "\n q quit" &lt;&lt; endl &lt;&lt; endl &lt;&lt; "Operation? ";
      cin &gt;&gt; operation;
  
  //Switch - the user does not want to quit
  
  switch (operation)
  {
  
  case 1: result=num1+num2;
      cout &lt;&lt; "Enter the first number to add: " &lt;&lt; endl;
      cin &gt;&gt; num1;
      cout &lt;&lt; "Enter the second number to add: " &lt;&lt; endl;
      cin &gt;&gt; num2;
      cout &lt;&lt; endl &lt;&lt; num1 &lt;&lt; " + " &lt;&lt; num2 &lt;&lt; " = " &lt;&lt; result;
      break;
  
  case 2: result=num1-num2;
      cout &lt;&lt; "Enter the first number to subtract: " &lt;&lt; endl;
      cin &gt;&gt; num1;
      cout &lt;&lt; "Enter the second number to subtract: " &lt;&lt; endl;
      cin &gt;&gt; num2;
      cout &lt;&lt; endl &lt;&lt; num1 &lt;&lt; " - " &lt;&lt; num2 &lt;&lt; " = " &lt;&lt; result;
      break;
  
  case 3: result=num1*num2;
      cout &lt;&lt; "Enter the first number to multiply: " &lt;&lt; endl;
      cin &gt;&gt; num1;
      cout &lt;&lt; "Enter the second number to multiply: " &lt;&lt; endl;
      cin &gt;&gt; num2;
      cout &lt;&lt; endl &lt;&lt; num1 &lt;&lt; " * " &lt;&lt; num2 &lt;&lt; " = " &lt;&lt; result;
      break;
  
  case 4: result=num1/num2;
      cout &lt;&lt; "Enter the dividend: " &lt;&lt; endl;
      cin &gt;&gt; num1;
      cout &lt;&lt; "Enter the divisor: " &lt;&lt; endl;
      cin &gt;&gt; num2;
      cout &lt;&lt; endl &lt;&lt; num1 &lt;&lt; " / " &lt;&lt; num2 &lt;&lt; " = " &lt;&lt; result;
      cout &lt;&lt; endl &lt;&lt; num1 &lt;&lt; " % " &lt;&lt; num2 &lt;&lt; " = " &lt;&lt; result;
      break;
  
  case 5: result=num1^num2;
      cout &lt;&lt; "Enter the base number " &lt;&lt; endl;
      cin &gt;&gt; num1;
      cout &lt;&lt; "Enter the power: " &lt;&lt; endl;
      cin &gt;&gt; num2;
      cout &lt;&lt; endl &lt;&lt; num1 &lt;&lt; " ^ " &lt;&lt; num2 &lt;&lt; " = " &lt;&lt; result;
      break;
  
  case 6: result=num1!=num2;
      cout &lt;&lt; "Enter a number: " &lt;&lt; endl;
      cin &gt;&gt; num1;
      cout &lt;&lt; endl &lt;&lt; num1 &lt;&lt; " ! " &lt;&lt; " = " &lt;&lt; result;
      break;
  
  default: 
      cout &lt;&lt; "That is an invalid operation!" &lt;&lt; endl;    
      break;
  
  } // switch statement closed
  
  cout &lt;&lt; endl &lt;&lt; "What operation would you like to perform:" &lt;&lt; endl &lt;&lt; " + addition\n - subtraction\n * multiplication\n / division\n ^ number to power\n ! factorial" &lt;&lt; "\n q quit" &lt;&lt; endl &lt;&lt; endl &lt;&lt; "Operation? ";
  cin &gt;&gt; operation; 
  
  return 0;
  } //main statement closed
  </code></pre>