title: Need help C++ calculator with word input
body: <p>Hi again I am attempting a Bjarne Stroustrup exercise from his PPP book. I have managed to do most of the exercises, however I am having problem with one. </p>
  
  <p>In this program the basic idea is to have a calculator which can take both integer and string input. The actual calculator part works fine and I can have integer inputs with no problem. My problem lies when trying to convert a string input say "one" to the integer one. </p>
  
  <p>My idea of how to do this was have a for loop run through my vector which stores numbers 1-10 in words, and when it finds an index which contains a string which matches the users input it uses the for loops counter variable; which should then equal the amount the user typed in. </p>
  
  <p>This idea should work, and Bjarne's sample code uses a similar idea, however mine is slightly different and doesn't seem to work, the problem I'm having appears to be the fact that when comparing the user input to the vector indexes it doesn't seem to find any matches, I've been messing around with it for hours and can't seem  to find the reason. Anyway here is the code:</p>
  
  <pre><code>//simple calculator program, users can input words 1-10 and an integer will be     returned. 
  
  // header files
  #include "../../std_lib_facilities.h"
  
  //global varible- vector set up here. 
  vector&lt;string&gt; numbers;
  
  //functions, one to initiliase vectors, one to get number, and a main function. 
  
  void initiliase() {  
  numbers.push_back ("zero");
  numbers.push_back ("one");
  numbers.push_back ("two");
  numbers.push_back ("three");
  numbers.push_back ("four");
  numbers.push_back ("five");
  numbers.push_back ("six");
  numbers.push_back ("seven");
  numbers.push_back ("eight");
  numbers.push_back ("nine");
  numbers.push_back ("ten");
  }
  
  int get_number(){
  char choice;
  string type_val;
  int val = 0;
  cout &lt;&lt; "do you wish to enter a number or word? n/w" &lt;&lt; endl;
  cin &gt;&gt; choice;
  
  if ( choice == 'n'){
  cin &gt;&gt; val;
  return val;
  }
  
  else if(choice == 'w'){
  cin &gt;&gt; type_val;
  for (int i = 0; i&lt;numbers.size(); i++){
      if (numbers[i] == type_val)
      val = i;
  else
      cout &lt;&lt; "number not found in vector.";
      return val;
   }
  }
  }
  
        void print_answer(int ans, char oper, int val1,int val2) {
  cout &lt;&lt; "Your Answer is:" &lt;&lt; ' ' &lt;&lt; val1 &lt;&lt; ' ' &lt;&lt; oper &lt;&lt; ' ' &lt;&lt; val2 &lt;&lt; ' ' &lt;&lt; '=' &lt;&lt;   ans &lt;&lt; endl;
  </code></pre>
  
  <p>}</p>
  
  <pre><code>void main() {
  
  initiliase(); 
  int val1, val2, answer;
  char op;
  val1 = get_number();
  val2 = get_number();
  cout &lt;&lt; "Please input operation:";
  cin &gt;&gt; op; 
  switch (op){
  
  case '+': cout &lt;&lt; "You have chosen addition!" &lt;&lt; endl;
        answer = val1 + val2;
        print_answer (answer, op, val1, val2);
        break;
  case '-': cout &lt;&lt; "you have chosen subtraction!" &lt;&lt; endl;
        answer = val1 - val2;
            print_answer (answer, op, val1, val2);
        break;
  case '*': cout &lt;&lt; "you have chosen multiplication!" &lt;&lt; endl;
            answer = val1 * val2;
            print_answer (answer, op, val1, val2);
        break;
  case '/': cout &lt;&lt; "you have chosen division!" &lt;&lt; endl; 
            answer = val1 / val2;
        print_answer  (answer, op, val1, val2);
        break;
  case '%': cout &lt;&lt; "you have chosen modulos!" &lt;&lt; endl;
        answer = val1 % val2;
        print_answer (answer, op, val1, val2);
        break;
  default: cout &lt;&lt; "incorrent operation" &lt;&lt; endl;
  }
  keep_window_open ("~");
  }
  </code></pre>