title: Trying to pass an array to a function and find the sum
body: <p>I am newbie to programming and I am trying to pass an array into a function and add all the elements together and return the sum. The problem is that I am getting a garbage value for the sum. I have researched on how to pass arrays to functions and I do not know if I'm supposed to use a pointer to pass arrays. I am not good with pointers anyways.</p>
  
  <p>Here is my code</p>
  
  <pre><code>#include &lt;cmath&gt;
  #include &lt;cstdlib&gt;
  
  using namespace std;
  float mean(int);
  int sum(int ARRZO[5]);
  
  int total;
  
  int main()
  {
  
      int ARRZ[5];
      char *inname = "example.txt";
      ifstream infile(inname);
  
      if (!infile) {
          cout &lt;&lt; "There was a problem opening file " &lt;&lt; inname &lt;&lt; " for reading." &lt;&lt; endl;
          return 0;
      }
      cout &lt;&lt; "Opened " &lt;&lt; inname &lt;&lt; " for reading." &lt;&lt; endl;
      for(int i=0; i&lt;11; i++)
      {
          while (infile &gt;&gt; ARRZ[i]) 
          {
              cout &lt;&lt; "Value from file is " &lt;&lt; ARRZ[i] &lt;&lt; endl;
          }
      }
  
      total=sum(ARRZ);
      cout&lt;&lt;"the sum of the elements in the array is"&lt;&lt;total&lt;&lt;endl;
  
      system("PAUSE");
  
      return 0;
  }
  
  
  int sum(int ARRZO[])
  {
      int sumz=0;
      for (int i=0; i&lt;5; i++)
      {
          sumz+=ARRZO[i];
          cout&lt;&lt;ARRZO[i];
      }
      cout&lt;&lt;sumz&lt;&lt;endl;
      return sumz;
  }
  </code></pre>