# Argh! Need help with program to get sum of integers between m and n inclusively

• 03-12-2002
Niloc1
Argh! Need help with program to get sum of integers between m and n inclusively
The program will print the sum of the integers between m and n inclusive, where m and n are user input values.

After writing the pseudocode, I went to work and have this as part of my source code:

while (m!=n) {
if (m>n) {
++n;
}
else {
++m;
}
}

I can't figure out how to do the rest of this problem and it's been driving me crazy! Any help would be greatly appreciated.

Colin
• 03-12-2002
Govtcheez
int total = 0;

while (m<=n) {
if (m>n) {
total += n;
n++;
}
else {
total += m;
m++;
}
}
• 03-12-2002
Deckard
Where a is the starting value, b is the ending value, and total is the sum of the count:
Code:

```for ( total = 0; a <= b; a++ )   total += a;```
• 03-12-2002
Niloc1
Thanks!
I've got it working, but I have one question. What is the += mean? I haven't seen that one yet.

Colin
• 03-12-2002
Govtcheez
i += 4

is the same thing as

i = i + 4
• 03-12-2002
Niloc1
Thanks again.