Your numerator (i) and your denominator (n) should increment by 2 each time, not one.
Also, you don't need to test if (i<100) since (i<n) at each step. Just test n.
Finally, on line 14, you are making a classic, non-obvious mistake. i/n is an integer value, since both i and n are integers. You must cast at least one of them to a float:
hahaha before I logged in here I was reading as TraikNeaj advised me, and I found the error as Duoas explain !!
Sometimes you need a harsh words to convinced yourself to look deeper, and as a result, here is the final code for anyone will search for the same problem ;)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<iostream>
usingnamespace std;
int main()
{
int i;
int n;
float sum=0;
for(i=1,n=i+2;i<n&&n<=100; i+=2,n+=2)
sum += (float)i/n;
cout<<"Sum = "<<sum;
return 0;
}
Thank you very much for your tips and review, Duoas.
Also thank you Tarik