I'm trying to write a function called (sumTo) that takes as arguments two integers. My function should use a loop to sum all of the numbers between the two (This includes the starting and ending numbers) and return the sum.
I want the function to allow for either argument to be the larger. for instance, passing the numbers 1, 5 or 5, 1 should return the same sum
From main I want to ask the user for two numbers, call the function, and print the sum when the function returns.
Here is an example:
Enter two number
1 5
The sum of all the numbers is 15
Here is the code I have to far? I've been working on this for a couple hours and have really confused myself, any help is greatly appreciated... Thank you in advance!!
#include<iostream>
using namespace std;
int main()
{
int x,y;
int sum;
int low;
int high;
cout<<"please input two integers " <<endl;
cin >> x >> y;
}
int sumTo()
for (int i = low; i<high; i++)
{
if(x <= y)
{
for (int i = x; i<=y; i++)
{
sum+=i;
}
cout<<sum;
}
else
{
for (int i = y; i<=x; i++)
{
sum+=i;
}
cout<<sum;
}
cout<< "the sum of your number is: " <<sum+=i <<endl;
}
return 0;
}