Formula is:

s_n = n/2 * (a0 + an)

for example,

sum from 10 to 15 is:

s_6 = 6/2 * (10 + 15 )= 75

where we note that 10 is the first term and 15 is the sixth term

More details here

Thanks firstPerson but I found another formula.

Okey, so I've found a formula that works and have now tried to write a program but I get the error messages:

"uninitialized local variable 'num1' used" and "uninitialized local variable 'num2' used"

```
#include <iostream>
using namespace std;
float calc_sum(float n, float a, float b);
float calc_av(float n, float sum);
void output(float sum, float average, float a, float b);
void input(float& a, float& b);
int main()
{
float num1, num2, n;
n=(num2-1)-(num1+1)+1;
input(num1, num2);
float total=calc_sum(n, num1, num2);
float middle=calc_av(n, total);
output(total, medel, num1, num2);
return 0;
}
float calc_sum(float n, float a, float b)
{
return n*((b-1)-(a+1))/2;
}
float calc_av(float sum, float n)
{
return sum/n;
}
void output(float sum, float average, float a, float b)
{
cout<<"Sum of the numbers between "<<a<<" and "<<b<<" = "<<sum<<endl;
cout<<"Average = "<<average<<endl;
}
void input(float& a, float& b)
{
cout<<"Input 2 numbers: ";
cin>>a>>b;
}
```

How do I fix it?

Your problem is that in line 12, you try to calculate the values of num1-1 and num2-1 before you have given values to num1 and num2.

If this information is not enough to allow you to fix your problem, then you don't really understand how variables work, and you need to go back to the beginning of your C++ book and start over.