title: C++ Program does not return the correct factorial value
body: <p>I'm fairly new to C++ and was attempting to write a program that uses a Do-While loop to calculate the sum from 1 to n where n is an input parameter, and uses a factorial function in a for loop to calculate the factorial of n. However, when the program is compiled I get results such as:</p>
  
  <p>The total from 1 to n (where n is five in this example) is 001ED2A8 or some other weird combination of numbers and letters. The same thing happens for my factorial result. I would appreciate any and all help I can get. Here is what I have so far: </p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  int total(int);
  int factorial(int);
  
  void main()
  {
      int n;
      cout &lt;&lt; "Please enter a positive number:";
      cin &gt;&gt; n;
      cout &lt;&lt; "The total from 1 to " &lt;&lt; n &lt;&lt; "is " &lt;&lt; total &lt;&lt; endl;
      cout &lt;&lt; "The factorial of " &lt;&lt; n &lt;&lt; " is: " &lt;&lt; factorial &lt;&lt; endl;
  }
  
  int total (int n)
  {
      int i, total;
  
      total = 0;
      i = 1;
      do
      {
          total = total + i;
          i = i + 1;
      } while (total &lt;= n);
      return total;
  }
  
  int factorial (int n)
  {
      int product = 1;
  
      for (;n&gt;0; n--)
      {
          product = n * product;
      }
      return product;
  }
  </code></pre>