# C# Heron Formula

• ### Question

• I'm honestly really stuck and have no idea where to even start with this. I've tried a few different ways of coding this but it comes back with so many errors I'm not sure if I'm even beginning to do it right.

Write an Application that reads the length of the sides of a triangle from the user. Compute the area using Heron's formula (below), in which s represents half of the perimeter of the triangle, and a, b, & c represent the lengths of the three sides. Print the area to three decimal places.

// Compute semi-perimeter and then area
s = (a + b + c) / 2.0d;
area = Math.Sqrt(s*(s-a) * (s - b) * (s - c));

This is for my visual C# class

Any kind of help would be appreciated!

Sunday, November 12, 2017 8:59 PM

• I finally got the answer on different forum, here is the proper code

``````using System;

namespace ex
{
public class Program
{
public static void Main(string[] args)
{
double s, area;
double a, b, c;

Console.WriteLine("Enter side #1");
Console.WriteLine("Enter side #2");
Console.WriteLine("Enter side #3");

s = (a + b + c) / 2;
area = Math.Sqrt(s * ( s - a) * (s - b) * (s - c));

Console.WriteLine("Area = {0}", area);
}
}
}``````

• Proposed as answer by Tuesday, November 14, 2017 1:28 AM
• Marked as answer by Friday, November 17, 2017 3:41 AM
Monday, November 13, 2017 1:23 AM

### All replies

• What I have so far, not sure if any of it is even right

The only error I'm receiving at the moment is CS5001 (Program does not contain a static "main" method suitable for an entry point

Any help is appreciated even if it's saying all of this is wrong

namespace Heron
{
class HeronsFormula
{
public static void main(String[] args)
{
Console.WriteLine("type tbh to find the area of triangle through heron's formula");
if (typedvalue == "tbh")
{
Console.WriteLine("Type the value of first side");
Console.WriteLine("Type the value of second side");
Console.WriteLine("type the value of third side");
double fside = double.Parse(side1);
double sside = double.Parse(side2);
double thside = double.Parse(side3);
double s = (fside + sside + thside) / 2.0;
double har = Math.Sqrt(s * (s - fside) * (s - sside) * (s - thside));
}
}
}
}

Sunday, November 12, 2017 9:23 PM
• what my last homework looked like done properly for Example

(not the same question)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cartylab
{
class average
{

static void Main(string[] args)
{
int number1;
int number2;
int number3;
int sum;
int average;

Console.Write("Enter first integer: ");

Console.Write("Enter second integer: ");

Console.Write("Enter third integer: ");

sum = number1 + number2 + number3;
average = sum / 3;

Console.WriteLine("average is {0}", average);
} // end Main
} // end class average
}

Sunday, November 12, 2017 10:52 PM
• Hi Moon_Kitten,

You probably have a Program class that's somehow conflicting with your HeronsFormula class ... look for that in your solution and if you still can't figure it out, let us see what that Program class looks like.

~~Bonnie DeWitt [C# MVP]

http://geek-goddess-bonnie.blogspot.com

Sunday, November 12, 2017 11:58 PM
• I can't figure it out and not sure where to go at this point
Monday, November 13, 2017 12:03 AM
• Somewhere, you must have a Program class in your solution, in addition to your HeronsFormula class ... where is that Program class and what does the code look like in it? If you could also post a screenshot of what your Solution Explorer window looks like that might help too.

~~Bonnie DeWitt [C# MVP]

http://geek-goddess-bonnie.blogspot.com

Monday, November 13, 2017 12:08 AM
• It won't let me post images because it says I'm not verified, not sure how to get verified
Monday, November 13, 2017 12:40 AM
• I don't know how to get verified either ... sorry (I *should* know, but I don't).

Can you post the image somewhere else, somewhere publicly accessible (like in a Public folder in OneDrive or DropBox, if you have an account ... or any other kind of public file sharing site)?

~~Bonnie DeWitt [C# MVP]

http://geek-goddess-bonnie.blogspot.com

Monday, November 13, 2017 12:56 AM
• https://stackoverflow.com/questions/47255485/c-sharp-heron-triangles?noredirect=1#comment81462089_47255485
Monday, November 13, 2017 1:00 AM
• Sorry, Moon_Kitten ... I don't know how I missed this from the very beginning. Your static void method is called main, when it should be called Main. C# is a case-sensitive language, as you probably know. And the static void Main method *must* be a upper-case M!

I didn't need the uploaded picture for that, but it suddenly hit me right in the face!  ;0)

~~Bonnie DeWitt [C# MVP]

http://geek-goddess-bonnie.blogspot.com

Monday, November 13, 2017 1:10 AM
• I finally got the answer on different forum, here is the proper code

``````using System;

namespace ex
{
public class Program
{
public static void Main(string[] args)
{
double s, area;
double a, b, c;

Console.WriteLine("Enter side #1");
Console.WriteLine("Enter side #2");
Console.WriteLine("Enter side #3");

s = (a + b + c) / 2;
area = Math.Sqrt(s * ( s - a) * (s - b) * (s - c));

Console.WriteLine("Area = {0}", area);
}
}
}``````

• Proposed as answer by Tuesday, November 14, 2017 1:28 AM
• Marked as answer by Friday, November 17, 2017 3:41 AM
Monday, November 13, 2017 1:23 AM
• Hello ,

If the issues has been solved, you could close the thread by marking  as answer, This can be beneficial to other community members reading this thread.

Sincerely,

Neil Hu

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

Wednesday, November 15, 2017 10:20 AM