Function call

Mar 19, 2015 at 5:46pm
Write your question here.
what should my function call be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;
int sigmaFromTo(int num1, int num2);
int main ()
{
int num1, num2;
cout << "Enter two integers: ";
cin >> num1 >> num2;
// function call
}
int sigmaFromTo(int from, int to)
{
int sum;
sum = 0;
for (int i=from; i <= to; i++)
	sum = sum +i;
return sum;
}
Mar 19, 2015 at 5:53pm
1. Create an integer variable to "catch" the sum with.
2. Call the function.

int sum = sigmaFromTo(num1, num2);
Last edited on Mar 19, 2015 at 5:53pm
Mar 19, 2015 at 7:19pm
can you explain what you mean to "catch" the sum?
Mar 19, 2015 at 7:24pm
When you call the function, you send in num1 and num2 right? Then you do some shit with it in the function, and then you return sum; Where is that sum gonna go? To Mars? To heaven? By catch I mean, you need to create a variable of the same sort, in this case integer, to insert that returning value.

Which means. This int sum that is in your main - int sum = sigmaFromTo(num1, num2);

Is now equal to whatever you returned from the function
Mar 20, 2015 at 6:17pm
oh okay, thank you for explaining it to me
Topic archived. No new replies allowed.