title: C++ program not getting desired output
body: <p>Would you please help me on this one</p>
  
  <p>i am running a simple c++ program and although i can get an output the way it is wriiten in book but when I modify it in a way which I think is logically correct then am not getting a correct answer. Beginner here.</p>
  
  <p>Original Program (working):</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      // make a program that finds the total of ages in a random family whose size we dont know
  
      // we will ask for input from the user multiple times using a loop
      // if user enters -1 program termintaes
  
      int age;
      int total = 0 ;
  
      cout &lt;&lt; "What is the age of the first person?"  &lt;&lt; endl ;
      cin &gt;&gt; age;
  
  
          while(age != -1)
          {
                  total  = total + age ;
              cout &lt;&lt; "What is the age of the next person?"  &lt;&lt; endl ;
              cin &gt;&gt; age;
  
  
          }
  
          cout &lt;&lt; "The total age is " &lt;&lt; total &lt;&lt; endl ;
  
          return 0;
  
  
  
  }
  </code></pre>
  
  <p>Modified one (not working dont know why)</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      // make a program that finds the total of ages in a random family whose size we dont know
  
      // we will ask for input from the user multiple times using a loop
      // if user enters -1 program termintaes
  
      int age;
      int total = 0 ;
  
      cout &lt;&lt; "What is the age of the first person?"  &lt;&lt; endl ;
      cin &gt;&gt; age;
  
        total  = total + age ;
  
  
          while(age != -1)
          {
  
              cout &lt;&lt; "What is the age of the next person?"  &lt;&lt; endl ;
              cin &gt;&gt; age;
  
                  total  = total + age ;
          }
  
          cout &lt;&lt; "The total age is " &lt;&lt; total &lt;&lt; endl ;
  
          return 0;
  
  
  
  }
  </code></pre>