#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int main()
{
int caltype;
int numorden;
int length, angle;
cout << "Type '1' for sine, '2' for cosine and '3' for tangent." << endl;
cin >> caltype;
switch (caltype) {
case 1:
cout << "Is the unknown length the numerator or the denominator? Type '1' for numerator and '2' for denominator." << endl;
cin >> numorden;
switch (numorden) {
case 1:
cout << "Type the length of the hypotenuse." << endl;
cin >> length;
cout << "Type in the angle." << endl;
cin >> angle;
cout << "sinangle = O/H" << endl;
cout << "sin" << angle << " = x/" << length << endl;
cout << length << "sin" << angle << " = x" << endl;
cout << "Therefore x = " << length *sin (angle);
break;
case 2:
cout << "Type the length of the opposite." << endl;
cin >> length;
cout << "Type in the angle." << endl;
cin >> angle;
cout << "sinangle = O/H" << endl;
cout << "sin" << angle << " = " << length << "/x" << endl;
cout << "xsin" << angle << " = " << length << endl;
cout << "Therefore x = " << length / sin (angle);
}
}
}
我现在正在制作的是一个程序,它将向您显示三角测量的步骤。出于某种原因,当相反的情况除以sin(30)时,它总是导致负数。这是为什么?该错误似乎发生在这一行:
cout << "Therefore x = " << length / sin (angle);
答案 0 :(得分:4)
答案 1 :(得分:0)
sin
函数将输入视为弧度:
sin (angle * M_PI/180);
其中M_PI = 3.141 ....,这是一个常数。