### Thread: I need help to sum numbers in c++

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Posts
2
Rep Power
0

#### I need help to sum numbers in c++

I have to create a program within 10 hours to sum numbers in this form:
for example: 43+44+46+49+53+...

I'm new at programming and i couldnt do it.. but i need it for school. I had it for homework.

Some help would be much appreciated..

• ptr2void disagrees : Good luck with that.
2. Originally Posted by festi19
3. The requirements are unclear. Are you saying that the user input is in that form, or are you merely showing us what calculation the program is to perform? If all the program does is sum, you don't need the + separator, you could use spaces or newline - that would be easier to process.
4. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Posts
2
Rep Power
0
The code that i was looking for was like this:

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
double v=0;
int i,c;
i=44;
c=2;

do
{
v=v+i;
i=i+c;
c=c+1;

}while (i<=121)

cout<<v;
return 0;
}

maybe i was unclear.. thanks for replies..
5. Slightly mor compact:

Code:
```#include <iostream>
using namespace std;

int main()
{
int v = 0 ;
int c = 1 ;

for( int i = 44; i <= 121; i += c )
{
v += i ;
c++ ;
}

cout << v ;

return 0;
}```
Perhaps your question should have been:

"Calculate the sum of the series of numbers 44 <=x <= 121, where each successive number x is n more then the previous one where n starts from 1 and increases by one on each iteration: e.g. 43+44+46+49+53+..."