Thread: How to convert angle degrees into radians

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Cryptanalyst
    Join Date
    Sep 2007
    Posts
    52

    How to convert angle degrees into radians

    Guys...I was adding more parts to that equation solver program to make it a calculator of sorts...I need to know how to change degrees into radians..some help please?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    PI radians == 180 degrees
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Did you consider google?

    This is the third or so on the list of MANY that come back if you enter "degrees to radians" into google.

    http://www.teacherschoice.com.au/Mat...les/Angles.htm

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Cryptanalyst
    Join Date
    Sep 2007
    Posts
    52
    Code:
     cout << "Enter angle in (d)degrees or (r)radians? - ";
                         if (r == 'd')
                         {
                               cout << "Enter angle theta (degrees) -";
                               cin >> degrees;
                               a = (degrees * 180)/pi;
                         }
                         else if (r == 'r')
                         {
                               cout << "Enter angle theta(radians) -";
                               cin >> radians;
                               a == radians;
                         }
    This then? And yeah I just checked google before Salem replied lol sorry...I'll be careful in future to use the forum as a last resort. And the "r" variable is a char variable I already declared in the Class.(as are degrees,radians and pi..)
    Last edited by SVXX; 10-01-2007 at 03:25 AM.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Your degrees to radians is wrong - try reading the page I posted for you.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Cryptanalyst
    Join Date
    Sep 2007
    Posts
    52
    Its the same one I used o.O damn I made a mistake

  7. #7
    Cryptanalyst
    Join Date
    Sep 2007
    Posts
    52
    It isn't working...Let me post the problem -:

    This is the first part.
    Code:
    class Program
    {
           private:
                   float a,x,b,c,D,d,f; //Teh math vars.
                   int n; //You guessed it....ANOTHER math variable.
                   long double radians, degrees, Sine, Tangent, Cosine, Arctan, Arcsine, Arccos; //Trigonometry.
                   char g[1]; //For the trigo section.
                                                              
           public:
                   void Case1(); //All of
                   void Case2(); //these
                   void Case3(); //are
                   void Case4(); //the 
                   void Case5(); //mathematical
                   void Case6(); //operations.
                   void Trigonometry();// Trigonometrics. 
                   void EXIT();  //The exit function.
                   void RorQ();  //The restart or quit function.
                   int exit;     //The exit value.
                   int exitRorQ; //The restart or quit value.
                   char rq[1];   // "r" or "q"?(char size 1)
                                 
    };
    The Trigonometrics Part
    Code:
    void Program::Trigonometry()
    {
                        double pi = 3.1416; //Again for trigo.
                        if (g == "M")
                         {
                               setcolor(7);
                               cout << "Enter angle theta (degrees) -";
                               cin >> degrees;
                               a = (degrees * pi)/180;
                               Sine = sin (a);
                               Cosine = cos (a);
                               Tangent = tan (a);
                               Arctan = atan (a);
                               Arccos = acos (a);
                               Arcsine = asin (a);
                               cout << "\nThe trigonometric ratiosare as follows -:\n";
                               setcolor(14);
                               cout << "Sin theta = " << Sine << endl;
                               cout << "Cos theta = " << Cosine << endl;
                               cout << "Tan theta = " << Tangent << endl;
                               cout << "Inverse Sin(Arcsine) theta = " << Arcsine << endl;
                               cout << "Inverse Cos(Arccos) theta = " << Arccos << endl;
                               cout << "Inverse Tan(Arctan) theta = " << Arctan << endl;
                         }
                         else if (g == "N")
                         { 
                               setcolor(7);
                               cout << "Enter angle theta(radians) -";
                               cin >> radians;
                               a == radians;
                               Sine = sin (a);
                               Cosine = cos (a);
                               Tangent = tan (a);
                               Arctan = atan (a);
                               Arccos = acos (a);
                               Arcsine = asin (a);
                               cout << "\nThe trigonometric ratiosare as follows -:\n";
                               setcolor(14);
                               cout << "Sin theta = " << Sine << endl;
                               cout << "Cos theta = " << Cosine << endl;
                               cout << "Tan theta = " << Tangent << endl;
                               cout << "Inverse Sin(Arcsine) theta = " << Arcsine << endl;
                               cout << "Inverse Cos(Arccos) theta = " << Arccos << endl;
                               cout << "Inverse Tan(Arctan) theta = " << Arctan << endl;
                         }
    }
    And the Case6 part
    Code:
    void Program::Case6()
    {
                         cout << "Enter angle in (M)degrees or (N)radians? - ";
                         cin >> g;
                         Trigonometry();
                         setcolor(7);
                         Sleep(3000);
    }
    The output after cout << "Enter angle"..... isn't coming..it just skips the if else statements and goes straight to the getch(); in main..

  8. #8
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    You could declare the multiplier as a constant:
    Code:
    const DEG_TO_RAD 0.0174532925;
    Then use call it in you program like:
    Code:
    radians = degrees * DEG_TO_RAD;
    It saves some extra calculations.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by SVXX View Post
    It isn't working...Let me post the problem -:
    So, I suspect you need a "cin.ignore()" after each cin >> somedouble, because cin >> somechar will otherwise get your "newline" that is left in the buffer after you entered the double number.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Cryptanalyst
    Join Date
    Sep 2007
    Posts
    52
    where exactly must I implement that code? In the main()?
    Code:
    int main() //Muhuhahahhahaha
    {
         Program OMGDOIT; 
         int y;
         C.exit = 1;
         int ch;          //Clearing input buffers.
         char buf[BUFSIZ];//Same.
         while(C.exit == 1)
         {
        
            cout << "\nWelcome to the Equation Solver!\n";
            cout << "\nChoose one of the following -:\n";         
            cout << "\n1. Find a quadratic equation's nature of roots\n";
            cout << "\n2. Find a quadratic equation's roots\n";
            cout << "\n3. Establish the Vičte relation of the roots and coefficients\n";
            cout << "\n4. Find a term of an arithmetic progression(AP)\n";
            cout << "\n5. Find the sum of the terms of an AP\n";
            cout << "\n6. Find the trigonometric values of an angle\n";
            cout << "\n7. Quit,noobs >_>\n";
            cin >> y;
            cin.ignore();
            
            switch(y)
            {         
                      case 1:
                          OMGDOIT.Case1();
                          getch();
                          OMGDOIT.RorQ();
                          break;
                      case 2:
                          OMGDOIT.Case2();
                          getch();
                          OMGDOIT.RorQ();
                          break;
                      case 3:
                          OMGDOIT.Case3();
                          getch();
                          OMGDOIT.RorQ();
                          break;
                      case 4: 
                          OMGDOIT.Case4();
                          getch();
                          OMGDOIT.RorQ();
                          break;
                      case 5:
                          OMGDOIT.Case5(); 
                          getch();
                          OMGDOIT.RorQ();
                          break;  
                      case 6:
                          cout.flush(); 
                          OMGDOIT.Case6();
                          getch();
                          OMGDOIT.RorQ();
                          break; 
                      case 7:
                           C.exit = 0;  
                           break;  
                      default: 
                          cout << "Enter a number in the list\n";
                          break;
            }
            clrscr(); //Clears screen maybe?
            }
                  
            return 0;
    }

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    > else if (g[0] == 'N' || 'n')
    I thought we explained this one already in another thread.

    else if (g[0] == 'N' || g[0] == 'n' )

    Or maybe
    else if ( toupper(g[0]) == 'N' )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    The trig functions take arguments in radians. You've correctly converted a from degrees to radians, then incorrectly converted it right back to degrees inside the arguments to each of the trig functions.

  13. #13
    Cryptanalyst
    Join Date
    Sep 2007
    Posts
    52
    I was thinking pretty much the same thing...it accepts arguements in radians. How do I make it accept args in degrees? Then I'd convert degrees to radians,feed it to the computer and get an output based on that. And Salem that if else works anyway :P

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    > And Salem that if else works anyway :P
    Oh I'm sure it compiles, and perhaps through some random chance you occasionally see what you expect to see.
    But for sure it is NOT the way to compare a variable with an upper case or lower case letter.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  15. #15
    Cryptanalyst
    Join Date
    Sep 2007
    Posts
    52
    Hmm k I see,I'll implement what you said...but what about the accepting args in degrees part..some help on that please

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Convert DegMinSec to Decimal Degrees
    By JacquesLeJock in forum C Programming
    Replies: 3
    Last Post: 11-21-2007, 11:59 PM
  2. Temperature conversion...
    By Onslaught in forum C Programming
    Replies: 3
    Last Post: 10-21-2005, 01:15 PM
  3. sin() and cos() that use degrees
    By dwks in forum C Programming
    Replies: 3
    Last Post: 05-14-2005, 04:29 PM
  4. Convert Char to Int Function
    By drdroid in forum C++ Programming
    Replies: 9
    Last Post: 02-19-2003, 12:53 PM
  5. Is this right
    By Granger9 in forum C Programming
    Replies: 6
    Last Post: 08-14-2002, 02:21 AM