# Law of Cosines converting to degrees error

• 02-17-2013
hungrymouth
Law of Cosines converting to degrees error
So I'm trying to find angles A,B,C using law of cosines and I want the answers to be in degrees and the formula to convert the answer to degrees is angle*PI/180. However the answer does not convert to degrees what am I doing wrong?

Code:

```#include "stdafx.h" #include <iostream> #include <iomanip> #include <cmath> #define PI 3.14 using namespace std; int main() {     double A,B,C,a,b,c,b1,b2,h,R,L,T,x;     //This is for angle a     a = 10.0;     b = 7.0;     c = 5.0;     A = (b*b+c*c-a*a)/(2.0*b*c);     A = acos(A)*PI/180.0;     cout <<"\n\n\t\tThe value of angle A      ="<<A;     //This is for angle b     a = 11.6;     b = 15.2;     c = 7.4;     B = (a*a+c*c-b*b)/(2.0*a*c);     B = acos(B)*PI/180.0;         cout<<"\n\n\t\tThe value of angle B      ="<<B;     //This is for angle c     a = 2.0;     b = 3.0;     c = 4.0;     C = (a*a+b*b-c*c)/(2.0*a*b);     C = acos(C)*PI/180.0;     cout<<"\n\n\t\tThe value of angle C      ="<<C;     cout<<"\n\n\n\n";             return 0; }```
• 02-17-2013
grumpy
To convert to degrees, multiply by 180.0/PI. You are dividing by that value.

There is also the inconvenient problem that PI is not equal to 3.14. It is only an approximation. You need to decide if it is a good enough approximation. The more usual approach is to initialise PI as a variable, say as 4.0*atan(1.0) (there are plenty of other formulae you can use). That doesn't exactly give PI either, but does give a value accurate to floating point precision on your machine.