gpt4 book ai didi

c++ - 将长度除以 sin(x) 总是会得出否定答案

转载 作者:搜寻专家 更新时间:2023-10-31 00:53:12 27 4
gpt4 key购买 nike

#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);

最佳答案

您需要将其转换为弧度:

sin (角度 * PI/180);

更新:

What is PI?

World Record values of PI

关于c++ - 将长度除以 sin(x) 总是会得出否定答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49483896/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com