How do you put in code on C++ [(cos^-1) which is found on calculators as shift cos]...

what I am trying to do is solve for theta...

cos (theta) = Fy/Fx

how would i put that in code?

Printable View

- 02-09-2005MyDestinyHow do...
How do you put in code on C++ [(cos^-1) which is found on calculators as shift cos]...

what I am trying to do is solve for theta...

cos (theta) = Fy/Fx

how would i put that in code? - 02-09-2005Salem
use the acos() function

- 02-09-2005Kaelin
Do you have an IDE, like Borland CBuilder, MS Visual C++, or anything to that effect? If so, usually you can use the help function to search when you're just looking for a function.

Searching cos would probably yield acos as an alternate result. - 02-09-2005MyDestiny
I use acos() but, it does not calculate properly

- 02-09-2005Kaelin
Are you assigning it to an integer variable? Make sure you're using a float.

- 02-09-2005AH_TzeQuote:

Originally Posted by**MyDestiny**

- 02-09-2005MyDestiny
what do u mean float?

i didn't assign it to anything - 02-09-2005MyDestiny
I keep getting...

-1.#IND

as my answer - 02-09-2005Kaelin
What are you doing with it?

You either need to use it in an expression or assign it to a variable.

float accepts decimal values. Integers, as you know, cannot - int in C++ is the same as a real-life integer where no decimal values are allowed - 02-09-2005DougDbugRadians?
All of the trig functions in <cmath> use radians, not degrees. Maybe that will help. (?)

- 02-09-2005Salem
Example

Code:`#include<stdio.h>`

#include<math.h>

int main(){

double angle = 0.5; /* this is in radians */

double c = cos( angle );

double d = acos( c );

printf( "%f %f %f\n", angle, c, d );

return 0;

}

- 02-09-2005KaelinQuote:

All of the trig functions in <cmath> use radians, not degrees. Maybe that will help. (?)

I think MyDestiny might be using integer containers but it's hard to say without seeing the code - 02-10-2005MyDestiny
I just wanted to let you all know that I figured out the answer... THANKS a bunch for your help! :)