Using a double number in while statement

I am working on a problem that outputs how many terms are used to determine the amount of terms to find different amounts of Pi, such as 3.0, 3.1, 3.14. Could anyone help me on this code, especially with using a double number in a while statement. the forumla is:

Pi = 4 x (1-1/3+1/5-1/7+1/9-1/11+1/13....)

Code:

`#include <iostream>`

#include <cmath>

#include <iomanip>

using namespace std;

double pif(double q);

int terms=0;

int main()

{double q=3.1;

cout << "Pi Value Terms\n--------------------------\n";

cout << fixed << setprecision(2);

cout << pif(q)<< " "<< terms << endl;

return 0;

}

double pif (double q)

{

int sign = -1;

double n=1.0;

double pi=0;

while (what would I put here to compare pi to a double?)

{

pi = sign *(1/(2.0*n-1.0);

sign = -sign

n++;

terms++;

}

pi*=4.0;

return pi;

}

Edit: Didn't check code, had to delete a segment to show where I needed assistance.

Changed the sign variation from a power to sign=-sign.