Hi there,
The Wallis product is defined here: http://en.wikipedia.org/wiki/Wallis_product
I am having a problem with the following code, which attempts to approximate the product:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n = 2; // initialise top counter as 2 for the first two terms
int x = 1; // initialise bottom counter as 1 for the first term
float Answer = 1;
// calculate the value for pi/2 using a for loop
for ( n ; n <= 1000; n += 2 )
{
Answer = Answer * ( (n*n) / ( x * (x + 2) ) );
x += 2;
}
cout << "The approximated value for pi/2 = " << Answer << endl;
cout << "The theoretical value for pi/2 = " << M_PI/2 << endl;
return 0;
}
My problem is that I always get a 1 (what I initialised it to) for the ouput of the approximated value. Where is my mistake?
Thanks :)