solving pi using series

Im trying to solve this pi using the Leibnitz formula,the input of the program will be the number of terms in the series that user want to sum up and the output of the program will be the summation of those terms.
I cant figure out whats wrong I keep getting and error message about pow being ambiguous.If anyone could point me in the right direction that would be most appreciated. Thanks in advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
    long int terms, count;
    long double pi=0;

        cout << "Enter the number of terms to use: " << endl;
        cin >> terms;

        for (count=1; count<=terms; count++)
{
        pi += pow(-1,count+1)/(2*count-1);
}
        pi= pi* 4;

        cout << "The value of pi based on the number of terms is:" << pi << endl;

return 0;


} // end main 
It is because the pow() function is overloaded in various ways, but none of them take an int as the first argument:
http://www.cplusplus.com/reference/clibrary/cmath/pow/

To fix it, make sure to specify the type of floating-point you wish as the first argument. Here I specify a long double:
15
16
17
{
        pi += pow(-1.0L,count+1)/(2*count-1);
}


D:\prog\cc\foo> a
Enter the number of terms to use:
5000
The value of pi based on the number of terms is:3.14139


Hope this helps.
Last edited on
Oh thank you so much! I got it working now.
Topic archived. No new replies allowed.