To start off, you need something to hold the sum, you need something to hold the current value of the denominator, and you need something to store the current sign. Taking all of that gets us:
Now you also need your loop:Code:double sum = 0.0; double denominator = 1.0; double sign = 1.0;
In the body of the loop you need to increment the sum by the current term (sign multiplied by 4.0 divided by the value of the denominator). Then, you need to increment the denominator by 2, and multiply the sign by -1 so that it flips from positive to negative on each loop iteration. You also need to print the current value of the sum.Code:for( int i = 0; i < 20; ++i ) { // What goes here? }