Nicko01
April 29th, 2007, 14:40
Hello. I was bored and decided to make a program for windows to calculate pi, but its not working...
:confused:
ok, heres what i wrote:
#include <iostream>
int main()
{
using namespace std;
long double pi;
unsigned long int denom;
bool subtract;
denom = 1;
subtract = true;
pi = 4;
while(true)
{
cout << pi;
cout << "\n";
if (subtract == true)
{
denom = denom + 2;
pi = pi-4/denom;
subtract = false;
}
else
{
denom = denom + 2;
pi = pi+4/denom;
subtract = true;
}
}
return 0;
}
it just prints out 3 repeatedly!
it seems like it's rounding off everything. Is there any way I can stop this from happening and can anyone tell me WHY this is happening?
I dont really need it for calculating pi, i have around 90 digits memorized :D
I just need to work on my programming skills....
thats the whole reason for this program.
(please dont just read this and then hit the back button without saying something)
:confused:
ok, heres what i wrote:
#include <iostream>
int main()
{
using namespace std;
long double pi;
unsigned long int denom;
bool subtract;
denom = 1;
subtract = true;
pi = 4;
while(true)
{
cout << pi;
cout << "\n";
if (subtract == true)
{
denom = denom + 2;
pi = pi-4/denom;
subtract = false;
}
else
{
denom = denom + 2;
pi = pi+4/denom;
subtract = true;
}
}
return 0;
}
it just prints out 3 repeatedly!
it seems like it's rounding off everything. Is there any way I can stop this from happening and can anyone tell me WHY this is happening?
I dont really need it for calculating pi, i have around 90 digits memorized :D
I just need to work on my programming skills....
thats the whole reason for this program.
(please dont just read this and then hit the back button without saying something)