title: C++ Initialized Variable Keeps Printing out as Zero Even though Function is Passed
body: <p>I passed a function to calculate the sum of all the numbers in an array but it outputs as 0 which is what I initialized it to. The function is in a separate file from the actual program (I also created a class called Stats). When I display the total sum in the function, it shows the correct number. It's only when I initialize it to 0 is where it goes wrong. How can I make it where when I pass the function, the total actually updates to the correct amount and not zero.</p>
  <pre><code>const int num = 12;
  class Stats
  {
  private:
      double stats[num];
      double total = 0;
  public:
      void setValue(double stats[num], int);
      double calcTotal(double stats[num], double);
  
  };
  
  double Stats::calcTotal(double stats[num], double total)
  {
      total = 0;
      for (int i = 0; i &lt; num; i++)
      {
          total += stats[i];
      }
      cout &lt;&lt; total;
      return total;
  }
  
  int main()
  {
      double rainFall[num];
      double total = 0;
  
      Stats rainStats;
  
      for (int i = 0; i &lt; num; i++)
      {
          cout &lt;&lt; &quot;What was the rain fall for month #&quot; &lt;&lt; i + 1 &lt;&lt; &quot; ?&quot; &lt;&lt; endl;
          cin &gt;&gt; rainFall[i];
          rainStats.setValue(rainFall, num);
      }
  
      rainStats.calcTotal(rainFall, total);
      cout &lt;&lt; total;
      return 0;
  }
  </code></pre>
  <p>It prints out 0 in <code>int main()</code> but in <code>calcTotal</code>, it is the correct amount.</p>