为什么这段代码会出错? [英] Why is this code giving error?

查看:164
本文介绍了为什么这段代码会出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有太多要解释,因为我自己是C#的初学者。但是我想用三面计算三角形的面积。并且代码给出了我的错误CS0149 - 方法名称预期。



以下是我的代码:

  class  Q6_CalculateAreaOfTriangle 
{
double sideA = .Parse(到Console.ReadLine());
double sideB = double .Parse(Console.ReadLine());
double sideC = double .Parse(Console.ReadLine());

public static void FindAreaWith3Sides( double sideA, double sideB, double sideC)
{
double 周长=(sideA + sideB + sideC)/ 2 ;
double pSubSidA = perimeter - sideA;
double pSubSidB =周长 - sideB;
double pSubSidC = perimeter - sideC;
double areaRaw = perimeter(pSubSidA * pSubSidB * pSubSidC); // 这是它给我带来问题的地方。它要求给出一种方法。为什么会这样?
double area = Math.Sqrt(areaRaw);
}


}





我的尝试:



没什么。因为我不知道从哪里开始和寻找什么。



但是我请求以非常容易理解的英语提供解释,因为我没有多说在C#所以你提到的事情我甚至都听不到。



提前感谢大家。

解决方案

如果您双击错误消息,它将带您到它发现错误的行。查看错误消息,并在代码中:

方法名称预期



 double areaRaw = perimeter(pSubSidA * pSubSidB * pSubSidC); 

只有一个

周长 double 变量:

双倍周长=(sideA + sideB + sideC)/ 2; 

不是方法,所以它查看你的代码,看到这个:

 double variable = aName(参数列表); 

并期望aName是一个方法。所以,它抱怨:你不能调用变量,这没有任何意义!



我认为你需要回到基本数学: 给出三面三角区域 - 苍鹭的公式 - 数学公开参考 [ ^ ]

所以,计算p:(a + b + c)/ 2

然后area = Sqrt(p *(p - a)*(p - b)*(p -c))

你计算了p,没关系 - 但是你需要乘法符号:

  double  areaRaw = perimeter *(p​​SubSidA * pSubSidB * pSubSidC); 


I do not have much to explain as I myself is a beginner in C#. However I wanted to calculalte the area of a triangle using its three sides. And the code is giving me error as CS0149 - Method Name Expected.

Following is my Code:

class Q6_CalculateAreaOfTriangle
        {
            double sideA = double.Parse(Console.ReadLine());
            double sideB = double.Parse(Console.ReadLine());
            double sideC = double.Parse(Console.ReadLine());

            public static void FindAreaWith3Sides(double sideA, double sideB, double sideC)
            {
                double perimeter = (sideA + sideB + sideC) / 2;
                double pSubSidA = perimeter - sideA;
                double pSubSidB = perimeter - sideB;
                double pSubSidC = perimeter - sideC;
                double areaRaw = perimeter(pSubSidA * pSubSidB * pSubSidC); //Here is where it gives me problem. It asks to give a method. Why is it so??
                double area = Math.Sqrt(areaRaw);
            }


        }



What I have tried:

Nothing. As dont know where to start from and what to look for.

However I request to please provide an explanation in very very easy to understand English as I have not covered much in C# so the things you mention I might not even have heard of.

Thanks in advance to everyone.

解决方案

If you double click on the error message, it will take you to the line that it found teh error on. Look at the error message, and at the code:

Method Name Expected


double areaRaw = perimeter(pSubSidA * pSubSidB * pSubSidC);

There is only one
And perimeter is a double variable:

double perimeter = (sideA + sideB + sideC) / 2;

not a method, so it looks at your code, sees this:

double variable = aName(parameter list);

and expects aName to be a method. so, it complains: you can't "call" a variable, that doesn't make any sense!

I think you need to go back to basic maths: Area of a triangle given three sides - Heron's Formula - Math Open Reference[^]
So, calculate p: (a + b + c)/2
Then area = Sqrt(p * (p - a) * (p - b) * (p -c))
You've calculated p, that's fine - but you need the multiply sign:

double areaRaw = perimeter * (pSubSidA * pSubSidB * pSubSidC);


这篇关于为什么这段代码会出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆