Thanks byOmer for replay soon. I have another problem.
How it look if i allow user to choose two number (2nd number is greater than first) and add all ranging from first to second number? Example : suppose I want to choose 5 and 22 and add all the number from 5 to 22 using while loop. Here 5 and 22 are user choice can be chosen bt "std::cin"
#include <iostream>
usingnamespace std;
int main()
{
int a,b;
cin>>a>>b;
int i = a;
int sum = 0; // you need to set it to 0 so that it starts from that number, otherwise it'll give you a huge random number.
while (i <= b)
{
cout << i << endl;
sum = sum + i; //everytime the loop runs, it will add counter value to the sum value.
i++;
}
cout<<"Sum of the numbers between "<<a<<" and "<<b<<" is "<<sum<<endl;
}