title: Exit a while loop with one specific key stroke in C++
body: <p>I am trying to exit a while loop with this one specific character key input <code>|</code>.
  The only way I figured out how is to transform the <code>int</code> user input in <code>char</code>. For some reason, when I input the <code>|</code> character when the program is running, I only receive: <code>Press any key to continue...</code>. My final goal (as I hope is visible from my code) is for the program to actually list all inputs in my vector and then terminate.</p>
  
  <p>I am new to C++ and very lost on this point. If anyone could point me in the right direction I will be very appreciative. </p>
  
  <p>I am running a Windows 8 Entreprise machine.</p>
  
  <p><strong>About the program</strong></p>
  
  <p>This is a simple program that takes user input of integers, adds them to a vector and compares the last two to see which one is bigger, smaller etc. </p>
  
  <p><strong>Full code is here</strong></p>
  
  <pre><code>#include "../../std_lib_facilities.h"
  
  // conversion of units to meters
  
  double funconvert(double x, string unit)
  {
      const double cm_m = 1.0 / 100.0, in_cm = 2.54, ft_in = 12;
      if (unit == "m")
          return x;
      else if (unit == "cm")
          return x = x * cm_m;
      else if (unit == "in")
          return x = x * in_cm * cm_m;
      else if (unit == "ft")
          return x = x * ft_in * in_cm * cm_m;
      else
          cout &lt;&lt; "Unknown unit value.\n";
  }
  
  // printing the large and the small variables
  void printresult(double smallest, double largest)
  {
      cout &lt;&lt; "the smaller value is: " &lt;&lt; smallest &lt;&lt; "\n";
      cout &lt;&lt; "the larger value is: " &lt;&lt; largest &lt;&lt; "\n";
  }
  
  int main() 
  {
      vector&lt;double&gt;numbers;
      double a, b, smallest, largest;
      char the_stop;
      string unit;
      cout &lt;&lt; "Please enter an intiger followed by a measurment unit [e.g 10cm]:";
  
      // Take input
      while (cin &gt;&gt; a)
      {
          char the_stop = a;
          cin &gt;&gt; unit;
          cout &lt;&lt; the_stop;
          // check if this is the first number entered
          if (numbers.size() == 0)
          {
              a = funconvert(a, unit);
              b = a;
              numbers.push_back(a);
              numbers.push_back(b);
          }
          else if (the_stop == '|')
          {
              // This is not working for some reason... ERROR
              sort(numbers);
              for (int i = 0; i &lt; numbers.size(); ++i)
                  cout &lt;&lt; numbers[i];
              break;
          }
          else
          {
              //assign a and b to the last two numbers in a vector
              a = funconvert(a, unit);
              numbers.push_back(a);
              a = numbers[(numbers.size() - 1)];
              b = numbers[(numbers.size() - 2)];
              // numbers.erase(numbers.begin()); // enable if desire to keep the vector empty
          }
  
          // find out which variable is larger and smaller
          if (a &gt; b &amp;&amp; (a/b-1) &gt;= 0.01)
          {
              smallest = b;
              largest = a;
              printresult(smallest, largest);
          }
          else if (a &lt; b &amp;&amp; (b / a - 1) &gt;= 0.01)
          {
              smallest = a;
              largest = b;
              printresult(smallest, largest);
          }
          else if ((a / b - 1) &lt; 0.01 &amp;&amp; (a / b - 1) != 0.00 || (b / a - 1) &lt; 0.01 &amp;&amp; (a / b - 1) != 0.00)
          {
              cout &lt;&lt; "the nubers are almost equal\n";
          }
          else
              cout &lt;&lt; a &lt;&lt; " equals " &lt;&lt; b &lt;&lt; "\n";
      }
      return 0;
  }
  </code></pre>
  
  <p><strong>Code UPDATED</strong></p>
  
  <pre><code>#include "../../std_lib_facilities.h"
  
  // conversion of units to meters
  
  double funconvert(double x, string unit)
  {
      const double cm_m = 1.0 / 100.0, in_cm = 2.54, ft_in = 12;
      if (unit == "m")
          return x;
      else if (unit == "cm")
          return x = x * cm_m;
      else if (unit == "in")
          return x = x * in_cm * cm_m;
      else if (unit == "ft")
          return x = x * ft_in * in_cm * cm_m;
      else
          cout &lt;&lt; "Unknown unit value.\n";
  }
  
  // printing the large and the small variables
  void printresult(double smallest, double largest)
  {
      cout &lt;&lt; "the smaller value is: " &lt;&lt; smallest &lt;&lt; "\n";
      cout &lt;&lt; "the larger value is: " &lt;&lt; largest &lt;&lt; "\n";
  }
  
  int main() 
  {
      vector&lt;double&gt;numbers;
      double a, b, smallest, largest;
      char the_stop;
      string unit;
      cout &lt;&lt; "Please enter an intiger:";
  
      // Take input
      while (cin &gt;&gt; a)
      {
  
          // check if the | character is pressed
          char the_stop = a;
          if (the_stop == '|')
          {
              cout &lt;&lt; "start";
              sort(numbers);
              for (int i = 0; i &lt; numbers.size(); ++i)
                  cout &lt;&lt; numbers[i];
          }
          else
          {
              cout &lt;&lt; "And now the unit value:";
              cin &gt;&gt; unit;
          }
  
          // check if this is the first number entered
          if (numbers.size() == 0)
          {
              a = funconvert(a, unit);
              b = a;
              numbers.push_back(a);
              numbers.push_back(b);
          }
          else
          {
              //assign a and b to the last two numbers in a vector
              a = funconvert(a, unit);
              numbers.push_back(a);
              a = numbers[(numbers.size() - 1)];
              b = numbers[(numbers.size() - 2)];
              // numbers.erase(numbers.begin()); // enable if desire to keep the vector empty
          }
  
          // find out which variable is larger and smaller
          if (a &gt; b &amp;&amp; (a/b-1) &gt;= 0.01)
          {
              smallest = b;
              largest = a;
              printresult(smallest, largest);
          }
          else if (a &lt; b &amp;&amp; (b / a - 1) &gt;= 0.01)
          {
              smallest = a;
              largest = b;
              printresult(smallest, largest);
          }
          else if ((a / b - 1) &lt; 0.01 &amp;&amp; (a / b - 1) != 0.00 || (b / a - 1) &lt; 0.01 &amp;&amp; (a / b - 1) != 0.00)
          {
              cout &lt;&lt; "the nubers are almost equal\n";
          }
          else
              cout &lt;&lt; a &lt;&lt; " equals " &lt;&lt; b &lt;&lt; "\n";
      }
      return 0;
  }
  </code></pre>