title: C++ function to find max & minimum values
body: <p>I am trying to make a function that will, once called upon, read values from a data file and give four outputs: Maximum Positive value, minimum positive value, maximum negative value, and minimum negative value. If there are no positive values it should output "No positive values," and the same for negative. <b>The major problem I am running into is getting it to return the correct minimum negative value.</b></p>
  
  <p>Here is what I have so far.</p>
  
  <pre><code>void maxMinimum (double x[], int n)
  {
     int i;
     double posMaximum;
     double posMinimum;
     double negMaximum;
     double negMinimum;
     double max;
     double min;
  
     posMaximum = x[0];
     for (i=0; i &lt;= n-1; i++)
     {
        if(x[i] &gt; posMaximum)
           posMaximum = x[i];
     }  
     cout &lt;&lt; "       Maximum positive value       = " &lt;&lt; fixed &lt;&lt; setprecision(2) &lt;&lt; setw(8) &lt;&lt; right &lt;&lt; posMaximum &lt;&lt; endl;
  
     posMinimum = x[0];
     for (i=0; i &lt;= n-1; i++)
     {
        if(x[i] &lt; posMinimum)   if(x[i] &gt; 0.0)
           posMinimum = x[i];
     }
     cout &lt;&lt; "       Minimum positive value       = " &lt;&lt; fixed &lt;&lt; setprecision(2) &lt;&lt; setw(8) &lt;&lt; right &lt;&lt; posMinimum &lt;&lt; endl;
  
     negMaximum = x[0];
     for (i=0; i &lt;= n-1; i++)
     {
        if(x[i] &lt; negMaximum)   if(x[i] &lt; 0.0)
           negMaximum = x[i];
     }
     cout &lt;&lt; "       Maximum negative value       = " &lt;&lt; fixed &lt;&lt; setprecision(2) &lt;&lt; setw(8) &lt;&lt; right &lt;&lt; negMaximum &lt;&lt; endl;
  
     negMinimum = x[0];
     for (i=0; i &lt;= n-1; i++)
     {
        if (x[i] &lt; 0.0 &amp;&amp; x[i] &lt; negMaximum)
        negMinimum = x[i];
     }
  
     cout &lt;&lt; "       Minimum negative value = " &lt;&lt; fixed &lt;&lt; setprecision(2) &lt;&lt; setw(8) &lt;&lt; right &lt;&lt; negMinimum &lt;&lt; endl &lt;&lt; endl;
  
     max = x[0];
     for (i=0; i &lt;= n-1; i++)
     {
        if(x[i] &gt; max)
           max = x[i];
     }
  
     min = x[0];
     for (i=0; i &lt;= n-1; i++)
     {
        if(x[i] &lt; min)
           min = x[i];
     }
  
     if(max &lt; 0.0)
         cout &lt;&lt; "       No positive values" &lt;&lt; endl;
     if(min &gt;= 0.0)
         cout &lt;&lt; "       No negative values" &lt;&lt; endl &lt;&lt; endl;  
  
  }
  </code></pre>
  
  <p>When executed the function will return positive values for the minimum negative value. Which to me makes no sense due to <code>if (x[i] &lt; 0.0 &amp;&amp; x[i] &lt; negMaximum)</code>. Can someone please tell me what I am missing?</p>
  
  <p>Note: Minimum negative value refers to the value closest to zero. Maximum negative value is farthest from zero. </p>
  
  <p><b>Thanks in advance!</b></p>