public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
abox.Text = "0";
bbox.Text = "0";
cbox.Text = "0";
c.Text = "0";
}
private void calc_Click(object sender, EventArgs e)
{// IF COS IS CHECKED
if (p.Checked)
{
//Declaring Variables
double a = Double.Parse(abox.Text);
double b = Double.Parse(bbox.Text);
double can = Double.Parse(cbox.Text);
//Run the methods for answers
double pAns = cos(a, b, can);
//Output answers
c.Text = string.Format("{0}", pAns);
}
// IF Law Of Cosines IS CHECKED
if (sin.Checked)
{ //Declaring Variables
double a = Double.Parse(abox.Text);
double b = Double.Parse(bbox.Text);
double can = Double.Parse(cbox.Text);
//Run the methods for answers
double sumA = LOCa(a, b, can);
double sumB = LOCb(a, b, can);
double answer = cos(a, b, can);
//Output answers
c.Text = string.Format("{0}", answer);
AngA.Text = string.Format("{0}", sumA);
AngB.Text = string.Format("{0}", sumB);
}
}//Method for plain Cosine
static double cos(double a, double b, double can)
{ //COS math
double sum = (a * a) + (b * b) - (2 * a * b * Math.Cos(can));
//Square root it
double answer = Math.Sqrt(sum);
return answer;
}//Law of cosine angle A
static double LOCa(double a, double b, double can)
{ //Sum = c
double sum = (a * a) + (b * b);
//Square root C
double answer = Math.Sqrt(sum);
//Law of cosines math
double sumA = ((b * b) + (sum * sum) + (-1 * (a * a))) / (2 * b * sum);
//Return the answer
return sumA;
}
//Law of cosine angle B
static double LOCb(double a, double b, double can)
{
double sum = (a * a) + (b * b);
double answer = Math.Sqrt(sum);
double sumB = ((a * a) - (b * b) + (sum * sum)) / (2 * b * sum);
return sumB;
}
}
}
这将是一个程序,它计算三角形一边的长度,给定另外两边的长度和夹角的值。三角形不必是直角三角形。另外两种方法是使用余弦定律计算其他两个角度值的其他方法。我的所有方法都有相同的错误,表明“没有给出的参数对应于所需的形式参数”一个“方法”(double,double,double ......)而且我已经查看过这个问题的问题和回答但是对我来说,这些都不够基本(我在高中时的第一堂课程)。任何解决方案?
答案 0 :(得分:0)
你不必写像
Double.Parse("ac.Text");
但
Double.Parse(ac.Text);
因为你必须传递这些控件的内容,而你传递字符串“ac.Text”而不是
和方法cos你没有传递任何参数,而你必须传递
cos(a,b, etc...
答案 1 :(得分:0)
您的方法LOCa
和LOCb
包含参数:
static double LOCa(double a, double b, double sumA, double answer, double ac, double sumB, double sum)
{
}
static double LOCb(double a, double b, double sumA, double answer, double ac, double sumB, double sum)
{
}
但你没有打电话给他们:
double sumA = LOCa();
double sumB = LOCb();
您需要提供参数,以便编译器可以在您的代码中找到它们。目前没有合适的方法,这就是你得到错误的原因。
我看代码越多,就越错。大多数参数应该是在方法中声明的变量:
static double LOCa(double a, double b)
{
//Sum = c
double sum = (a * a) + (b * b);
//Square root C
double answer = Math.Sqrt(sum);
//Law of cosines math
double sumA = ((b * b) + (sum * sum) + (-1 * (a * a))) / (2 * b * sum);
//Return the answer
return sumA;
}
并且这样调用:
double sumA = LOCa(a, b);
与LOCb相同。