title: Min and Max function return gibberish value when array is not full
body: <p>I need to create a program that collects user input until the user presses 0 or has inputted 10 values. Then I need to create a function, without using built-in to get the minimum and maximum values. However, when 9 or less values are inputted, the minimum and maximum function return a random value. Here is my code:</p>
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int getMin(int array[], int n);
  int getMax(int array[], int n);
  
  int main()
  {
      int array[10];
  
      cout &lt;&lt; &quot;This program will ask the user to input various numbers (positive or negative but not zero) and perform basic statistics on these numbers.\n&quot;;
  
      for(int i=0; i&lt;10; i++){
          cout&lt;&lt;&quot;\nInput an integer: &quot;;
          cin&gt;&gt;array[i];
  
          if(array[i]==0) {
          break; 
          }
      }
  
      int n = sizeof(array) / sizeof(array[0]);
      cout &lt;&lt; &quot;Minimum element of array: &quot; &lt;&lt; getMin(array,n) &lt;&lt; &quot;\n&quot;;
      cout &lt;&lt; &quot;Maximum element of array: &quot; &lt;&lt; getMax(array,n);
      return 0;
  }
  int getMin(int array[], int n)
  {
      int minimum = array[0];
      for (int i = 1; i &lt; n; i++)
          if (minimum &gt; array[i]) {
              minimum=array[I];
          }
      return minimum;
  }
  
  int getMax(int array[], int n)
  {
      int maximum = array[0];
      for (int i = 1; i &lt; n; i++)
          if (maximum &lt; array[i]) {
             maximum=array[I];
          }
      return maximum;
  }
  </code></pre>
  <p>How do I make it so even if I input less than 10 values, it returns the correct minimum and maximum value?</p>