title: Programming help Loop adding
body: <p>I know this probably really simple but Im not sure what im doing wrong...</p>
  
  <p>The assignment states:</p>
  
  <p>For the second program for this lab, you are to have the user enter an integer value in the range of 10 to 50. You are to verify that the user enters a value in that range, and continue to prompt him until he does give you a value in that range.</p>
  
  <p>After the user has successfully entered a value in that range, you are to display the sum of all the integers from 1 to the value entered.</p>
  
  <p>I have this so far:</p>
  
  <pre><code>#include &lt;iostream.h&gt;
  
   int main () {
  
  int num, sum;
  
    cout &lt;&lt; "do-while Loop Example 2"
         &lt;&lt; endl &lt;&lt; endl;
  
    do {
      cout &lt;&lt; "Enter a value from 10 to 50: ";
      cin &gt;&gt; num;
      if (num &lt; 10 || num &gt; 50)
        cout &lt;&lt; "Out of range; Please try again..."
             &lt;&lt; endl;
    } while (num &lt; 10 || num &gt; 50);
  
      {
    int i;
    int sum = 0;
  
    for (num = 1; num &lt;= 50; num ++) 
    sum = sum + num;
  }
  
    cout &lt;&lt; endl &lt;&lt; "The sum is " &lt;&lt; sum &lt;&lt; endl;
  
  return 0;
  
  }
  </code></pre>
  
  <p>Im just not sure exactly what i'm doing wrong... I keep getting the wrong sum for the total... </p>