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?

This is a discussion on *How do...* within the **C++ Programming** forums, part of the General Programming Boards category; How do you put in code on C++ [(cos^-1) which is found on calculators as shift cos]...
what I am ...

- 02-09-2005 #1

- Join Date
- Feb 2005
- Posts
- 19

## How 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-2005 #2
use the acos() function

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.

I support http://www.ukip.org/ as the first necessary step to a free Europe.

- 02-09-2005 #3

- Join Date
- Feb 2005
- Posts
- 44

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-2005 #4

- Join Date
- Feb 2005
- Posts
- 19

I use acos() but, it does not calculate properly

- 02-09-2005 #5

- Join Date
- Feb 2005
- Posts
- 44

Are you assigning it to an integer variable? Make sure you're using a float.

- 02-09-2005 #6

- Join Date
- May 2003
- Posts
- 82

Originally Posted by**MyDestiny**

- 02-09-2005 #7

- Join Date
- Feb 2005
- Posts
- 19

what do u mean float?

i didn't assign it to anything

- 02-09-2005 #8

- Join Date
- Feb 2005
- Posts
- 19

I keep getting...

-1.#IND

as my answer

- 02-09-2005 #9

- Join Date
- Feb 2005
- Posts
- 44

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-2005 #10

- Join Date
- Sep 2001
- Posts
- 1,398

## Radians?

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

- 02-09-2005 #11
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; }

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.

I support http://www.ukip.org/ as the first necessary step to a free Europe.

- 02-09-2005 #12

- Join Date
- Feb 2005
- Posts
- 44

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-2005 #13

- Join Date
- Feb 2005
- Posts
- 19

I just wanted to let you all know that I figured out the answer... THANKS a bunch for your help!

- Exactly how to get started with C++ (or C) today
- C Tutorial
- C++ Tutorial
- 5 ways you can learn to program faster
- The 5 Most Common Problems New Programmers Face
- How to set up a compiler
- 8 Common programming Mistakes
- What is C++11?
- Creating a game, from start to finish

- How to create a shared library on Linux with GCC - December 30, 2011
- Enum classes and nullptr in C++11 - November 27, 2011
- Learn about The Hash Table - November 20, 2011
- Rvalue References and Move Semantics in C++11 - November 13, 2011
- C and C++ for Java Programmers - November 5, 2011
- A Gentle Introduction to C++ IO Streams - October 10, 2011