"There is no argument given that corresponds to the required formal parameter " " of "形式1.LOCa(双,双,


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;

        }

    }
}

这将是一个程序,根据其他两条边的长度和包含的角度的值,计算三角形一侧的长度。三角形不必是直角三角形。另外两种方法是使用余弦定律计算其他两个角度的值的附加方法。我所有的方法都有相同的错误,指示"没有给出对应于"方法(双精度,双精度,双精度...(所需的形式参数"a"的参数我已经查看了这个问题的问题和回答,但它们对我来说都不够基本(我在高中的第一堂编程课上(。有什么解决办法吗?

你不必写成

Double.Parse("ac.Text");

Double.Parse(ac.Text);

因为您必须传递此类控件的内容,而要传递字符串"ac.文本"改为

对于方法 cos,您没有传递任何参数,而您必须传递

cos(a,b, etc...

您的方法LOCaLOCb都有参数:

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 相同。

相关内容

最新更新