Problems with acos (math.h)

This is a discussion on Problems with acos (math.h) within the C++ Programming forums, part of the General Programming Boards category; Hi. I tried to make a program that generates the angles of a triangle using the length of the sides. ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    2

    Problems with acos (math.h)

    Hi.

    I tried to make a program that generates the angles of a triangle using the length of the sides. With a calculator, you divide one side by the other and then press SHIFT+COS (or 2nd+COS etc.) and the correct angle is displayed (in degrees!).

    In C++, I think that this "SHIFT+COS" must be the acos-function (included in math.h).
    So I tried the following:

    .
    .
    .
    #include <math.h>
    .
    .
    .
    double side1,side2,angle;
    .
    .
    .
    angle=acos(side1/side2);
    .
    .
    .

    Everything of the code is correct (yes, I took the correct two sides) but the acos-function doesn't calculate the right angle (in my example, the angle should be about 37 degrees, the acos says something about 0.69).

    So, has anyone got an idea what the problem is? Perhaps it isn't the acos that I have to use or I did something wrong or is it really the acos that doesn't calculate correctly?

    Thanks in advance,

    -- pyrocommander --

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    the math functions give answers in radians, not degrees

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    2

    RE: acos

    Thanks man, that helped a lot!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 05:35 AM
  3. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 08:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 03:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21