title: Printing out sum of each pair of vector elements - C++
body: <p>I'm trying to printing out sum of each pair of adjacent elements in a vector. But the code shown below is not giving me the correct result. Anyone can help me with this?</p>
  
  <p>int main()
  {</p>
  
  <pre><code>vector &lt;int&gt; num(10);
  vector &lt;int&gt; res(5);
  int get = 0;
  int range = 0;
  
  for (int i = 0; i != 10; ++i) {
      cin &gt;&gt; get;
      num.push_back(get);
  }
  
  while (range != num.size()) {
      int c = 0;
      int c1 = c + 1;
      res.push_back(num[c] + num[c1]);
      if (c == 0)
          c = 1;
      c *= 2;
      ++range;
  
  }
  cout &lt;&lt; res[7];
  
  for (int u = 0; u != res.size(); ++u) {
      cout &lt;&lt; res[u] &lt;&lt; " ";
  }
  
  return 0;
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Update: -</strong></p>
  
  <p>I've changed this code as you mentioned in the comment section, but when I compile it showing me a debug error.</p>
  
  <p>I able to read 1-10 integers into the 'num' vector. But when I hit enter after read all the integers into the vector, this debug error happens.</p>
  
  <pre><code>int main()
  {
  
      vector &lt;int&gt; num;
      vector &lt;int&gt; res;
  
      int get = 0;
      int range = 0;
      int c = 0, c1 = 0;
  
      for (int i = 0; i != 10; ++i) {
          cin &gt;&gt; get;
          num.push_back(get);
      }
  
      while (range != num.size()) {
          c1 = c + 1;
          res.push_back(num[c] + num[c1]);
          if (c == 0)
              c = 1;
          c *= 2;
          ++range;
  
      }
  
      for (int u = 0; u != res.size(); ++u) {
          cout &lt;&lt; res[u] &lt;&lt; " ";
      }
  
      keep_window_open();
      return 0;
  }
  </code></pre>