我正在尝试制作一个三角函数计算器。
这是我的表单https://gyazo.com/6faecac18159d84b33497e06d864aa3d
当我输入3个数字时,应该得到正确的结果。 实际结果的图片= https://gyazo.com/aa65ab502c0337ece0753b72029fa34a
但是我似乎无法弄清楚我的代码出了什么问题。
这是我的代码
double B = Convert.ToDouble(textBox5.Text);
double C = Convert.ToDouble(textBox1.Text);
double side_A = 180 - B - C;
string ConverterForA = Convert.ToString(side_A);
textBox2.Text = ConverterForA;
double calculatorForb = Math.Cos(C * (Math.PI / 180));
string Converterforb = Convert.ToString(calculatorForb);
textBox3.Text = Converterforb;
double calculatorForc = Math.Sin(C * (Math.PI / 180));
string ConverterForc = Convert.ToString(calculatorForc);
textBox6.Text = ConverterForc;
三角形的边
//double C = Convert.ToDouble(textBox1.Text);
//double A = Convert.ToDouble(textBox2.Text);
//double b = Convert.ToDouble(textBox3.Text);
//double a = Convert.ToDouble(textBox4.Text);
//double B = Convert.ToDouble(textBox5.Text);
//double c = Convert.ToDouble(textBox6.Text);
您会看到结果混合在一起。我输入了10,50和80
答案 0 :(得分:0)
我很难跟踪您的变量名以及要与之匹配的变量名,因此已经重命名了-我建议您仔细研究一下并使它们对您有意义。但是,以下工作(假设在输入数据时要小心-您显然需要在某些阶段添加一些验证。
double anglec = Convert.ToDouble(text_anglec.Text);
double angleb = Convert.ToDouble(text_angleb.Text);
//double anglea = Convert.ToDouble(text_anglea.Text);
double length1 = Convert.ToDouble(text_length1.Text);
//double length2 = Convert.ToDouble(text_length2.Text);
//double length3 = Convert.ToDouble(text_length3.Text);
double anglea = 180 - angleb - anglec;
text_anglea.Text = anglea.ToString();
double length2 = length1 * Math.Sin(anglea * (Math.PI / 180));
text_length2.Text = length2.ToString();
double length3 = length1 * Math.Cos(anglea * (Math.PI / 180));
text_length3.Text = length3.ToString();