Program that estimates pi using the squeeze theorem

Hello. I am a c++ programmer and I am in 8th grade. I have been programming for a month now. I just learned how to use the squeeze theorem to derive pi (sandwiching the circle between 2 shapes), and I tried to build a program that does it. However, in order to find pi here, you need to find the area of the shapes sandwiching pi, which requires using the sine and tangent functions. Whenever I put in a number to test my program, specifically for the sin function, I always get a result that is incorrect.

For example, on my calculator sin(45) = .707
but on my program sin(45) = .85 or something like that.

I included math.h and I tried using sinh() and tanh() but it didn't really work.
The sin and cos functions expect the angle in radians, so it should be
1
2
3
sin(45*M_PI/180);
//or
sin(0.25*M_PI);

Of course, this already uses pi, which is the value supposed to be calculated.
Last edited on
Here is a reference for you:
http://www.cplusplus.com/reference/clibrary/cmath/sin/

And it says:
Compute sine
Returns the sine of an angle of x radians.


So the function isn't wrong, you just need to put your angle in radians instead of degrees. I know, bummer, and it more or less needs you to know pi anyways which defeats the purpose.
Hahahha. It doesn't really matter if it uses pi or not, for now, at least. I just want to make a basic functional program. So M_PI is a constant in the c++ library?
@Volatile Pulse:
Thanks, I had already tried that. I just didn't know what radians were, so I was confused. I just wanted to show the estimate of pi and then find the accuracy of the estimation in order to prove Archimedes' theorem.
Topic archived. No new replies allowed.