Sum of numbers

--Originally published at PZ

For me this was much more difficult than the last programs because I used loop like For and return, I also used int to create a inclusive sum between the to numbers, for me this was the most difficult becuase I didnt know how te say to the computer to do an inclusive sum between the numbers. I also searched in a lot of blogs but I finally found one that helped me a lot, not also for the code also because in the discussion of the blog the people where sharing pages to understand how to make loops.

#include <iostream>
using namespace std;
int sum(int base, int limit);
int main()
{
int a, b;
cout << “Please give us the lower bound “;
cin >> a;
cout << “Please give us the upper bound:”;
cin >> b;
cout <<“The sum from “<<a<<” to “<<b<<” is:”<< sum(a, b)<<endl;
return 0;
}

int sum(int base, int limit)
{
int sum = 0;
for (int i = base; i <= limit; i++){
sum += i;
}
return sum;
}

Source:http://www.dreamincode.net/forums/topic/239277-sum-of-all-numbers-in-a-range-c-primer-problem/