Have to use loop to find sum between two integers. HELP!!

I have to use a loop to find the sum between two integers that the user chooses. The integers can be negative. Im having trouble as I am a very new user to C++.
Thanks!!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 #include<iostream>
using namespace std;

int main()
{
	int number1, number2, sum;
	cout << "Input two integers: ";
	cin >> number1 >> number2;
	sum = 0;
	for (int i = number1; i <= number2; i++)
	{
		sum += i;
	}
	cout << "Sum of the values from " << number1 << " to " << number2 << " is: " << sum << endl;
	sum = 0;	
	for (int i = number1 + 1; i<number2; i++)
	{
		sum += i;
	}
	return 0;
}
a
What's wrong with it?
Input two integers: 1 10
Sum of the values from 1 to 10 is: 55
Its not doing them from negative integers. And my Output is supposed to look like this:

Input two integers: -9, 4

Sum of values from -4 through 9 is:
-9 + -8 + -7 + -6 + -5 + -4 + -3 + -2 + -1 + 0 + 1 + 2 + 3 + 4
= -35
Input two integers: -9 4
Sum of the values from -9 to 4 is: -35

And for printing the sum, you can just put a cout statement in your for loop that prints the current number and a plus sign.
(You'll need an extra check for the last number to make sure you don't print a plus sign after that)
@ Long Double Main

Hi long double main! I'm still supposed to be bobthezealot, but my account got hacked, and I can't log on. I made a new account! Nice to see you again!

@ The question

Psst...
You put the letter a at the end of your post!
Topic archived. No new replies allowed.