--Originally published at |Blogging through my thoughts|
¡Hello , programmer and curious friends! This is my fourth program , created using Cygwin and Atom. For this task , my classmates and I were instructed to create a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).
For example, the sum from 6 to 10 would be 0 + 6 + 7 + 8 + 9 + 10.
I decided to use a loop to calculate the sum, because my programming teacher Ken Bauer, wanted us to practice repetitive work.
The resources that helped me were:
-How to think like a computer scientist.
-cpluplus.com
-Programming hub, mobile app.
I added some extra steps, because I wanted to show more information to the users , like:
-Both numbers are the same. Give me a correct range.
– The sum is also executed if the user writes the upper and lower bound in the wrong order.
Here you will find my code and some captures:


#include
using namespace std;
int sum(int min,int max);
int main(){
cout << “This program prints the sum of numbers in a range(inclusive):” << endl;
int a,b;
cout << “Enter the lower bound:” << endl; cin >> a;
cout << “Enter the upper bound:” << endl; cin >> b;
if (a<b){
cout << “The sum from ” << a << ” to ” << b << ” is: ” << sum (a,b) << endl; } else if (a>b){
cout << “The sum from ” << a << ” to ” << b << ” is: ” << sum (b,a) << endl;
}
else {
cout << “Both numbers are the same. Give me a correct range.” << endl;
}
return 0;
}
int sum (int base , int limit)



