Inclusive While Loop

Hello,

How can I get my while loop to run inclusive? I can run the program to get near results but because I add 1 to the first variable that number gets added to the result. How can I get the output without the added 1 needed to complete the loop? If that makes sense.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;
int main ()
{
	int a, b, c = 0 ;
	cout << "Enter an integer: ";
	cin >> a;
	cout << "Enter another integer: ";
	cin >> b;
	while (a <= b)
	{
		a = a + 1;
		c = c + a;
		
		cout << c << endl;
	}
}
Maybe I'm misunderstanding you completely
but just do it this way around.

1
2
c = c + a;
a = a + 1;
I'm not entirely sure what you're asking. Answer these questions and I will do my best to help you.

1. What do you want your program to do? Can you give me some example input/output?

2. How many times do you want your loop to run? The-second-number-you-input minus the-first-number-you-input times?
Thanks Just had to do it other the other way around.
Topic archived. No new replies allowed.