0

In the program given below, Math.Sqrt function is throwing an error that is "Expression denotes a variable', where amethod group' was expected." What seems to be problematic here?


using System;
class program{
    static void Main(){
        Console.WriteLine("Enter the sides(a,b,c) of a triangle  :");
        int a = Convert.ToInt16(Console.ReadLine());
        int b = Convert.ToInt16(Console.ReadLine());
        int c = Convert.ToInt16(Console.ReadLine());
        double s = (a+b+c)/2;     
        double area = Math.Sqrt(s(s-a)(s-b)(s-c));
        if (a==b&&b==c){
            Console.WriteLine("This is an Equilateral trangle");
        }
        else if(a==b&&b!=c||a!=b&&b==c){
            Console.WriteLine("This is an Isosceles trangle");
        }
        else{
            Console.WriteLine("This is an Scalene trangle");
        }
    }
}here

1 Answers1

1

C# will not assume a multiplication in the same way you write down an equation, and instead will see s(s-a) as a function called s that takes a parameter of s-a. You need to explicitly state the multiplication sign:

double area = Math.Sqrt(s*(s-a)*(s-b)*(s-c));
DavidG
  • 113,891
  • 12
  • 217
  • 223