title: How to use functions in c++?
body: <p>I am supposed to get the following code to display something along the lines of: "The sum of 1 to 10 is 55." (The larger number can be any number that was just the example I got.) I was given this code to use.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  // Compute the sum of all of the numbers from 1 to n where n
  // is a natural number
  // use the formula: n(n+1)/2
  void compute_sum(int limit) // compute_sum function
  {
  int sum_to_limit;
  sum_to_limit = limit * (limit + 1) / 2;
  }
  int main()
  {
  int sum = 0;
  int maxNumber;
  // get the maxNumber for the function call
  cout &lt;&lt; "Enter a whole number greater than 0" &lt;&lt; endl;
  cin &gt;&gt; maxNumber;
  // call compute sum
  compute_sum(maxNumber); // Call to compute_sum function
  // display the sum calculated by the compute_sum function
  cout &lt;&lt; "The sum of 1 to " &lt;&lt; maxNumber;
  cout &lt;&lt; " is " &lt;&lt; sum &lt;&lt; endl;
  
  return 0;
  } 
  </code></pre>
  
  <p>I do not understand how funcctions work at all and do not have any idea how I would go about getting this to work. The only thing I know about this (and this is from the teacher) is that the change required is not major. "Note: If you are making major changes to the main and compute_sum funtions you are probably
  doing way too much work." I have tried changing the function to an int function with a return but I could not get it to work properly (most likely due to not knowing how functions work). So can someone please help me?</p>