title: Average of # Sequence
body: <p>I'm having trouble figuring out the loop in the average function. User enters sequence and if the number of numbers in the sequence is greater than 0, output avg of the numbers and repeat for another sequence. If the sequence has no numbers, exit program. </p>
  
  <p>I understand that I'm telling the average function to return 0 when sum = 0 and that's why it exits after the 1st sequence (I think). </p>
  
  <p>Any suggestions as to how to avoid that? Pseudocode if possible!</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  
  double average();
  
  int main () 
  {
      while( average() ) 
      {
      }
  }//end main
  
  double average() 
  {
      double n, sum = 0;
      int count = 0;
  
      printf ( "Enter sequence: " );
      while( scanf( "%lf", &amp;n ) )
      {
          sum += n;
          count++;
      }
  
      if( sum &gt; 0 )
      {
          printf( "average is %.2f\n", sum/(double)count );
          return 1;
      }
      else
          return 0;
      }
  }
  </code></pre>
  
  <p>Here is my output:</p>
  
  <pre><code>Enter sequence: 3 4 5 x
      average: 4.00
  Enter sequence: Press any key to continue . . .
  </code></pre>