I'm new to C++, and I'm having trouble figuring out where my issue is. I'm trying to ask the user for how far they want to find pi using the Gregory - Leibniz series, but whenever I put any number I always get 4 (1 from the loop). Thanks in advance :)
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
double x = 0;
double doubleTerms = 0;
cout << "How many terms of pi do you want?" << endl;
cin >> doubleTerms;
cout << "Thanks the amount of terms you want for pi is: " << doubleTerms << endl;
//n is the value for where each number is
//z is to change the number into a negative
//x is to add up into the total value
for(int n = 0; n < doubleTerms; n++)
{
double z = 1 / (2 * n + 1);
if((n % 2) == 1)
{
z = z * -1;
}
x = (x + z);
}
double finalValue = 4 * x;
cout << "The number is: " << finalValue << endl;
system("pause");
return 0;
}