The homework question said to rearrange statements and remove part of code that made it calculate incorrectly. I'm lost on this and have been searching multiple places and trying different things. This is a beginning C++ class, too, so, for homework in the first half I can't very well be going into complicated strings of advanced coding and pretend I'm that great when I can't even do this. I'd mostly appreciate hints and nudges toward understanding it, but straight answers suffice, too.
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
double pi = 0;
long i;
double n;
cout << "Enter the value of n: ";
cin >> n;
cout << endl;
for (i = 1; i < n; i++ )
pi = 4 * pi;
if (i % 2 == 0)
pi = pi + (1 / (2 * n + 1));
else
pi = pi - (1 / (2 * n + 1));
cout << endl << "Pi: " << pi << endl;
return 0;
}