-
Anyone know C++?
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:
Code:
#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)
-
i don't know.
check it against tuts here- http://www.cprogramming.com/tutorial.html
-
I know some C++, but not enough to actually help anyone...
...Oh and your code is horrible! :(
-
make both pi and denom an unsigned long double, or just add a .0 to the end of the 4. The problem is that it's getting turned back into an int because it thinks it doesn't need the precision.