title: Extracting the minimum value from a file using a while loop c++
body: <p>I am required to set the minimum value (minValue) equal to -1 in my declarations. How do I, using the || (or condition) within my while loop, extract a minimum value from a positive set of numbers considering that a negative value concludes the program? Also, the double average variable (average), is not calculating the intended value. For example, if the value is supposed to be 35.7789, it is returning 35.0000. I am also intending for the average value to return with no decimal point when unnecessary. For example, if the user enters a negative value first, the average value should be 0 as opposed to 0.0000. How do I manipulate the average variable in order to do so?</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  
  using namespace std;
  
  int main()
  {
      int intVal;
      int sum = 0;
      int maxValue = -1;
      int minValue = -1;
      double average = static_cast&lt;double&gt;(0);
      int count = 0;
      int evenCount = 0;
      int oddCount = 0;
      cout &lt;&lt; endl &lt;&lt; &quot;Enter an integer (negative value to Quit):  &quot;;
      cin  &gt;&gt; intVal;
      cout &lt;&lt; endl;
     
      
      while(intVal &gt;= 0)
      {
        if(intVal &gt; maxValue)
            maxValue = intVal;
        if(intVal &lt; minValue)
            minValue = intVal;
          count ++;
          sum += intVal;
          
          if(intVal &gt; 0)
              average = sum / count;
          
          if(intVal % 2 == 0)
              evenCount ++;
          else
              oddCount ++;
          
          cout &lt;&lt; &quot;Enter an integer (negative value to Quit):  &quot;;
          cin  &gt;&gt; intVal;
          cout &lt;&lt; endl;
      }
      
          cout &lt;&lt; fixed &lt;&lt; setprecision(4);
          cout &lt;&lt; &quot;Values entered:&quot; &lt;&lt; setw(8) &lt;&lt; right &lt;&lt; count &lt;&lt; endl;
          cout &lt;&lt; &quot;Sum of numbers:&quot; &lt;&lt; setw(8) &lt;&lt; right &lt;&lt; sum &lt;&lt; endl;
          cout &lt;&lt; &quot; Average value:&quot; &lt;&lt; setw(8) &lt;&lt; right &lt;&lt; average &lt;&lt; endl;
          cout &lt;&lt; &quot; Maximum value:&quot; &lt;&lt; setw(8) &lt;&lt; right &lt;&lt; maxValue &lt;&lt; endl;
          cout &lt;&lt; &quot; Minimum value:&quot; &lt;&lt; setw(8) &lt;&lt; right &lt;&lt; minValue &lt;&lt; endl;
          cout &lt;&lt; &quot;  Even numbers:&quot; &lt;&lt; setw(8) &lt;&lt; right &lt;&lt; evenCount &lt;&lt; endl;
          cout &lt;&lt; &quot;   Odd numbers:&quot; &lt;&lt; setw(8) &lt;&lt; right &lt;&lt; oddCount &lt;&lt; endl;
          cout &lt;&lt; endl;
          
  }
  </code></pre>