Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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.
Posted
Updated 28-Sep-18 0:39am
Comments
Herman<T>.Instance 28-Sep-18 6:28am    
perimeter is a double type variable and not a method

1 solution

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:
C#
double areaRaw = perimeter * (pSubSidA * pSubSidB * pSubSidC);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900