Write a program that will add the terms of an infinite geometric series. The program should read the first term (a) and the common ratio (r) for the series. It should then compute the sum in two ways: by formula ( s=a1−r), and by adding the individual terms until the answer agrees with the formula to 7 significant digits. Then print the formula answer, the answer found by adding the terms, and the number of terms that were added. Print the sums to at least ten places. Verify input with a while loop. Two real values are equal to n significant digits if the following condition is true:|a-b|<|a*
this is what i have so far #include<iostream> #include<cmath> using namespace std; int main() { int i=0; double sum, r, a, b; double rNew, rTotal=0; a=1; r=.1; rNew=r; sum=0; while(fabs(a-b)>=fabs(a*1E-7) { rTotal=rNew; rNew=rNew*r; sum+=(a/(1-rTotal)); b=sum; cout<<sum<<" "; } //sum=(rTotal*a)+a; /*cout.setf(ios::fixed); cout.setf(ios::showpoint); cout<<sum<<endl;*/ }
Join our real-time social learning platform and learn together with your friends!