title: Exit program when enter key is pressed
body: <p>I have a simple c++ calculator and I am trying to have the program exit on empty input (Enter Key). I can get the program to exit and continue; however the program ignores the first character.</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;conio.h&gt;
  
  using namespace std;
  float a, b, result;
  char oper;
  int c;
  
  
  void add(float a, float b);
  void subt(float a, float b);
  void mult(float a, float b);
  void div(float a, float b);
  void mod(float a, float b);
  
  
  int main()
  {
  // Get numbers and mathematical operator from user input
  cout &lt;&lt; "Enter mathematical expression: ";
  
  int c = getchar(); // get first input
  if (c == '\n') // if post inputs are enter
      exit(1); // exit
  
  else {
  
      cin &gt;&gt; a &gt;&gt; oper &gt;&gt; b;
  
  
      // operations are in single quotes.
      switch (oper)
      {
      case '+':
          add(a, b);
          break;
  
      case '-':
          subt(a, b);
          break;
  
      case '*':
          mult(a, b);
          break;
  
      case '/':
          div(a, b);
          break;
  
      case '%':
          mod(a, b);
          break;
  
      default:
  
          cout &lt;&lt; "Not a valid operation. Please try again. \n";
          return -1;
  
      }
  
  
      //Output of the numbers and operation
      cout &lt;&lt; a &lt;&lt; oper &lt;&lt; b &lt;&lt; " = " &lt;&lt; result &lt;&lt; "\n";
      cout &lt;&lt; "Bye! \n";
      return 0;
  }
  }
  
  //functions
  void add(float a, float b)
  {
  result = a + b;
  }
  
  void subt(float a, float b)
  {
  result = a - b;
  }
  
  void mult(float a, float b)
  {
  result = a * b;
  }
  
  void div(float a, float b)
  {
  result = a / b;
  }
  
  void mod(float a, float b)
  {
  result = int(a) % int(b);
  }
  </code></pre>
  
  <p>I tried using putchar(c) it will display the first character, but the expression wont use the character.</p>