I am trying to figure out how to make a program so that when I enter a starting number and an ending number all numbers between that are added up.
For Example
First Number: 1
Second Number: 5
The program will: 1+2+3+4+5 = answer
This is what I have so far
#include<iostream.h>
#include<math.h>
main()
{
int firstnum, secondnum, x, answer;
answer = 0;
cout<<"Please enter beginning term: ";
cin>>firstnum;
cout<<"Please enter ending term: ";
cin>>secondnum;
while(firstnum<=secondnum)
{
answer = firstnum++;
{
cout<<answer<<endl;
}
} return 0;
}
This prints
1
2
3
4
5
How would I get it to 1 + 2 + 3 + 4 + 5 using the while loop?
Any help would be appreciated.
Thank You
[email protected]