### Sine rule problems.

Hello, I am trying to make a program that can use the sine rule to calculate the missing side of a triangle. However, the program keeps returning incorrect answers. Thanks for any help!
 ``12345678910111213141516171819202122232425262728293031`` ``````#include #include #include #include #include using namespace std; double a_side; double a_angle; double b_angle; double sin_rule_side_function (double a_side, double a_angle, double b_angle) { return (sin(b_angle) * a_side / sin(a_angle)); } int main (){ cout << "Insert your A side." << endl; cin >> a_side; cout << "Insert your A angle." << endl; cin >> a_angle; cout << "Insert your B angle." << endl; cin >> b_angle; double b_angle_answer; { double b_angle_answer = sin_rule_side_function(a_side, a_angle, b_angle); cout << "Your answer is " << b_angle_answer << endl; } system("pause"); }``````
Before looking at the program a stupid question: are you using degrees or radians?
Not so stupid question, the answer is default :S I have no idea how to change it.

Thanks for the quick response!
Last edited on
Is there any particular reason why starting on line 26 there is another curly parantheses block?
The angles in C use radians because it's faster to calculate it that way. If you want to use degrees you'll have to convert it.

EDIT: Faster, or easier as the case my be.
Last edited on
How do I do that?

Well, a full-circle angle in degrees is 360 degrees, right?

So to convert from radians to degrees multiply by (360 / 2 pi).

To convert from degrees to radians multiply by (2 pi / 360).
Last edited on
45 degrees is 1/4 pi, 30 degrees is 1/6 pi.
Sorry, I am really having trouble converting the units correctly. I've been trying to figure it out for a while and I still can't seem to do it. Any ideas?
 ``12345678910111213141516171819202122`` ``````#include #include using namespace std; const double pi = 3.1415926535897932385; int main() { double degrees = 30; double radians = degrees * pi / 180.0; // Convert degrees to radians cout << "the sine of " << degrees << " degrees is " << sin(radians) << endl; double num = sqrt(3)/2.0; radians = asin(num); degrees = radians * 180.0 / pi; // Convert radians to degrees cout << "The angle whose sine is " << num << " is " << degrees << " degrees" << endl; return 0; }``````

Output:
 ```the sine of 30 degrees is 0.5 The angle whose sine is 0.866025 is 60 degrees```

Last edited on
Thank you! :)
Topic archived. No new replies allowed.