#include <iostream>
usingnamespace std;
int main(int argc, char** argv) {
float num;
float term;
float first;
float total;
float sum;
cout<<"Please enter a number: ";
cin>>num;
cout<<"Please enter the number of terms you would like to calculate: ";
cin>>term;
first=(term-1)/num;
for (int i=2;i<=term;++i){
total+=(term-i)/(num*=num);
}
sum=term+first+total;
cout<<sum<<endl;
return 0;
}
Total after loop 1 : 1
Total after loop 2 : 1.1875
Total after loop 3 : 1.953125
Total after loop 4 : 1.1953277587890625
Total after loop 5 : 1.1953277587890625
Sum = term: 6 + first: 2.5 + Total: 1.195327758789025
Sum = 9.695327758789025
So that is why Your program is outputting that number.
What is the problem you are trying to solve? Can you post more information about that? Sorry, I cannot solve your issue at this point, my intuition about your actual program is not giving me a solution, I do hope that my post helps you tho.