I have an assignment to write a program asking the user to input 2 integers then output the addition of the integers from smallest to largest (eg, input 2 & 6, out put would be the sum of 2 + 3 + 4 + 5 + 6 is 20). Addition must be from smallest to largest regardless of the order the integers are input (eg, input 12 & 6, addition would start at 6) and if user puts the same number in for both integers the out put would be that number. Unfortunately, neither lectures nor book deal with this situation. All examples start with a programmed number and count to a user imput max value or ask user for ONE number and counts a programmed number of times. I have no idea even how to start this, everything I've tried fails to compile. Any help would be appreciated.
First, you need to read in the two numbers.
Next, you need to find the maximum and minimum of the two numbers.
Then, count from the minimum to the maximum.
I really appreciate the reply but I know WHAT I have to do; my problem is I have no idea how to even start. I don' t know what kind of loop problem this is - for, while, do while???? I found one example in the text book using a "for" loop that asked for two integers so I decided to try a "for" loop. Below is what I tried even though I was pretty sure it wouldn't work (and it didn't!!):
/*The program asks user to input two integers,
then adds the from lowest to highes.t*/
#include <iostream>
using namespace std;
int main ()
{
int num; // Loop counter variable.
int x, y; // To hold user input integers.
cout << "Input 2 integers: ";
cin >> x, y;
cout << "Sum of values from" << x " through " << y "is:";
for ((x > y; x++; num == y;) || (y > x; y++; num == x;) || (x == y; num == x))
#include <iostream>
usingnamespace std;
int main()
{
int sum;
int x,y;
cout << "Input 2 integers: ";
cin >> x, y;
//determine min and max, put min in x, max in y.
//(you may have to use a temporary helping variable)
sum=0; //<- don't forget this!
while(true) //<- this loops forever unless you break
{
//add x to sum
//increase x by one
if (/*x is greater than y*/) break;
}
//print results
return 0;
}