You're going to need:
- a for loop to iterate a counter variable (e.g. n) from 1 to i, inclusive.
- a variable to accumulate the sum
- floating-point division, for example sum += static_cast<double>(n) / (n + 1);
@OP
Here's a supplementary start, with an alternative hack to the static_cast - try it with 1 instead of 1
Your next challenge is to design the function. Perhaps even get user input for the limit and produce some user-friendly output.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
int main()
{
int LIMIT{3};
double sum{0};
for(int i = 1; i < LIMIT; i++)
{
sum += i / (1. * ( i + 1 ));
}
std::cout << sum << '\n';
return 0;
}