Thread: Law of Cosines converting to degrees error

  1. #1
    Registered User hungrymouth's Avatar
    Join Date
    Oct 2012

    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?

    #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;
        return 0;

  2. #2
    Registered User
    Join Date
    Jun 2005
    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.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CAIRO - error when converting txt to pdf
    By leonardoadoado in forum C++ Programming
    Replies: 17
    Last Post: 12-05-2012, 01:38 PM
  2. Replies: 2
    Last Post: 12-04-2012, 07:28 AM
  3. Error converting to same format?
    By FlyingIsFun1217 in forum C++ Programming
    Replies: 19
    Last Post: 07-07-2010, 12:39 PM
  4. sin() and cos() that use degrees
    By dwks in forum C Programming
    Replies: 3
    Last Post: 05-14-2005, 04:29 PM
  5. Slope to degrees
    By zMan in forum C Programming
    Replies: 3
    Last Post: 05-06-2003, 07:46 AM