How do i properly calculate an angle for a triangle?

So for a C++ project at college, we need to make a program where you input the lengths of 2 sides of a right angle triangle, and then the program calculates the hypotenuse, and the two angles. So i got the hypotenuse calculated easily but im having trouble with the angles.
Here is the code for calculating one of the angles:

double angleA = asin((x/z));
angleA = angleA*(180/3.14);

the second line is my attempt to convert radians to degrees but im having trouble with it. i searched all over Google for formulas for converting radians to degrees and the only one i could find was: Angle*(180/pi)

also what library do i need to include to use math.pi? i tried iomanip but that didnt work

Anyways could someone please help me get this figured out?
Last edited on
The library is cmath and pi is M_PI
In terms of the formula remember pi radians is 180 degrees therefore pi/2 is equal to 90 degrees. From here you can work out what 1 degree is in radians and vice versa. As for using pi try doing the following.

http://stackoverflow.com/questions/1727881/how-to-use-the-pi-constant-in-c

EDIT: Seems Oria got to it first.
Last edited on
I just posted this in a similar thread today.

To convert radians to degrees:
1
2
3
4
5
6
7
8
#define PI 3.14159265358 //Go as long as you want, the longer the more accurate
#define radianstodegrees(R)((180.0 * R) / PI)//Converts Radians to Degrees

//Implement it
double answer;
double radians; //the angle
answer = radianstodegrees(radians);
 


There might be a better way to do it though, I have always used this though.
And if you have never used define before you put it below the #include(s)
Last edited on
Topic archived. No new replies allowed.