title: Neverending while-loop in C++ that is to end when an input string == no?
body: <p>I am trying to write a code that sums two input integers, and keeps on adding an integer for as long as the user wishes to do so, and if the user wants to exit simply writes "no". This does not work, however. When you write "no" it just goes crazy and adds and subtracts seemingly random numbers. My main function simply runs <code>inputIntegersUsingLoopAndPrintSum()</code></p>
  
  <pre><code>void inputIntegersUsingLoopAndPrintSum() {
      int input;
      string answer;
  
      int sum = inputIntegersAndPrintSum();
  
      cout &lt;&lt; "do you wish to continue? if you don't; write no\n";
      getline(cin, answer); //If you wish to continue
      while (answer != "no") {
          input = inputInteger();
          sum = sum + input;
          cout &lt;&lt; "new sum is: " &lt;&lt; sum &lt;&lt; "\n";
          cout &lt;&lt; "do you wish to continue? if you don't; write no\n";
          getline(cin, answer);   
      }
  
  
      int inputInteger() {
         int tall;
         cout &lt;&lt; "Skriv inn et tall: "; 
         cin &gt;&gt; tall;
         return tall;
  
         int inputIntegersAndPrintSum() {
             int input1, input2, sum;
             input1 = inputInteger(); //bruker den som returnere en verdi
             input2 = inputInteger();
  
             sum = input1 + input2;
             cout &lt;&lt; "Summen av tallene: " &lt;&lt; sum &lt;&lt; "\n";
             return sum;
         }
  </code></pre>