title: How to average positive inputs until a negative input is given
body: <p>How can I accept and average positive numbers? When a negative number is entered, it should terminate the loop and display the average (excluding the negative number).</p>
  
  <pre><code>#include &lt;iostream&gt; 
  
  using namespace std ;
  int main () {
      int x,counter=0,sum;
      float avg;
      while (x&gt;0) {
          if(x&lt;0) {
              sum+=x;
              counter++;
              continue;
          } else if  (x&gt;0) {
              cin&gt;&gt;x;
              sum+=x;
              counter ++;
          }
      }
      avg=(float)sum/counter;
      cout&lt;&lt;avg&lt;&lt;endl;
      return 0 ;
  }
  </code></pre>