/*Write a program that asks the users for two integers, x and y.
It should then add up all the integers between (and including)
x and y and output the result.If x and y are equal to each other,
your program should ask the user for two numbers again
and repeat until the user provides different values.*/
#include<iostream>
usingnamespace std;
int main()
{
//variables
int x, y, num, sum = 0;
// enter 2 numbers x and y
cout << (" Enter the first number \n");
cin >> x;
cout << (" Enter the second number \n");
cin >> y;
/*If x and y are equal to each other, your
program should ask the user for two numbers again
and repeat until the user provides different values.*/
if (x == y)
{
cout << " The numbers equal each other. enter the two numbers again \n";
cin >> x;
cin >> y;
}
//Your program should work correctly if x > y or if x < y.
int higher_num;
int lower_num;
if (x > y)
{
higher_num = x;
lower_num = y;
}
else
{
higher_num = y;
lower_num = x;
}
/*It should then add up all the integers between
(and including) x and y and output the result.*/
int num = lower_num;
while (num <= higher_num, )
{
cout << (sum += num);
num++;
}
cout << "\n The sum of all the integers between \n";
cout << " (and including) " << x << " and " << y << " is " << sum << endl << endl;
system("pause");
return 0;
}