Function call

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;
}
1. Create an integer variable to "catch" the sum with.
2. Call the function.

int sum = sigmaFromTo(num1, num2);
Last edited on
can you explain what you mean to "catch" the sum?
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
oh okay, thank you for explaining it to me
Topic archived. No new replies allowed.