I am basically trying to make a program for a calculator. I am struggling with how to do the sine calculation. this calculation will take place at line 158. Any help will be highly appreciated. Thanks
The sine rule (look it up) says lengthA / sin(angleA) = lengthB / sin(angleB)
rearranging, sin(angleB) = sin(angleA) * lengthB / lengthA
That gives the sine of angle B. To find the angle itself, use the arcsine function. angleB = asin(sin(angleA) * lengthB / lengthA)
In terms of the c++ code. First, make sure that all of the variables for angles or lengths are of type double, not int.
The, replace this line cout << "the answer is..." <<
with this: cout << "Angle B is " << asin(sin(angleA) * lengthB / lengthA) << endl;
Of course that uses angles expressed in radians. If you want it to work in degrees, first define the value of pi, constdouble PI = 3.1415926535897932385;
then use this: cout << "Angle B is " << (180.0/PI)*asin(sin(angleA*PI/180.0) * lengthB / lengthA) << endl;