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?
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?
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.
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.
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..)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; }
Last edited by SVXX; 10-01-2007 at 03:25 AM.
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.
Its the same one I used o.O damn I made a mistake
It isn't working...Let me post the problem -:
This is the first part.
The Trigonometrics PartCode: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) };
And the Case6 partCode: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; } }
The output after cout << "Enter angle"..... isn't coming..it just skips the if else statements and goes straight to the getch(); in main..Code:void Program::Case6() { cout << "Enter angle in (M)degrees or (N)radians? - "; cin >> g; Trigonometry(); setcolor(7); Sleep(3000); }
You could declare the multiplier as a constant:
Then use call it in you program like:Code:const DEG_TO_RAD 0.0174532925;
It saves some extra calculations.Code:radians = degrees * DEG_TO_RAD;
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.
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; }
> 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.
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.
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
> 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.
Hmm k I see,I'll implement what you said...but what about the accepting args in degrees part..some help on that please