# floating point values

Printable View

• 12-28-2005
jmarsh56
floating point values
i am trying to do the following:

program that reads two floating-point values representing angles and displays a message stating which angle has the greater tangent value. Note that the trigonometric functions in the math library expect angles in radians, not degrees. 360 degrees = 2 x pi radians, so 45 degrees would be about 0.785 radians.

I have come up with code that takes in 2 numbers and displays the highest values. What I am stuck on is the calculations part. I am searching online and reading the books. Any help in this area will be great. Here is the code I have so far:

Code:

``` #include <iostream> using std::cout; using std::cin; using std::endl; int main() { float x,y; cout<< "Enter the first angle: "; cin>> x; cout<< "Enter the second angle: "; cin>> y; if ( x > y ) cout << " The highest angle is "<< x <<endl; else cout<< "The highest angle is "<< y <<endl; }```
• 12-28-2005
hk_mp5kpdw
All you have to do is compare tan(angle1) with tan(angle2). If tan(angle1) > tan(angle2) then output angle1 else output angle2.

Note: you should also be #include'ing <cmath> if you are going to be calling the tan function in your code. Also, your angles would be better as doubles and not floats.
• 12-28-2005
jmarsh56
i am not sure what you mean. dont i have to put in somewhere the formula to figure out which angle is larger? also i am not sure what you mean by tan(angle)
• 12-28-2005
hk_mp5kpdw
Quote:

Originally Posted by jmarsh56
dont i have to put in somewhere the formula to figure out which angle is larger?

Quote:

Originally Posted by jmarsh56
i am trying to do the following:

program that reads two floating-point values representing angles and displays a message stating which angle has the greater tangent value.

I'm working off of what you said in the original post... which is finding the angle has the greater tangent value, not finding the greater angle. To do that you must call the tangent function which is called tan and pass into it the angle (in radians). So... as an example to display the tangent of an angle input by the user:

Code:

```double angle; cout << "Enter an angle (in radians): "; cin >> angle; cout << "The tangent of " << angle << " radians is " << tan(angle) << '.' << endl;```
Output:
Code:

```Enter an angle (in radians): .785398 The tangent of .785398 radians is 1.```
• 12-28-2005
jmarsh56
thanks, i added that in with a few more lines i came up with and received the answer i was looking for. thanks again
• 12-28-2005
dwks
The remark about a double being better than a float was because doubles are much more accurate.