-1

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.

The Question is below

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!

Update 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");
      string typedvalue = Console.ReadLine();
      if (typedvalue == "tbh") {
        Console.WriteLine("Type the value of first side");
        string side1 = Console.ReadLine();
        Console.WriteLine("Type the value of second side");
        string side2 = Console.ReadLine();
        Console.WriteLine("type the value of third side");
        string side3 = Console.ReadLine();
        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));
        Console.ReadLine();
      }
    }
  }
}

Update 2

picture of code and error

hnefatl
  • 5,860
  • 2
  • 27
  • 49
Luna Kitten
  • 1
  • 1
  • 5

1 Answers1

1

Here is a quick solution that should work.

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");
            a = double.Parse(Console.ReadLine());
            Console.WriteLine("Enter side #2");
            b = double.Parse(Console.ReadLine());
            Console.WriteLine("Enter side #3");
            c = double.Parse(Console.ReadLine());

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

            Console.WriteLine("Area = {0}", area);
        }
    }
}
hnefatl
  • 5,860
  • 2
  • 27
  • 49
Tamir Nakar
  • 933
  • 1
  • 10
  • 17
  • Yes this works and prompts properly thanks! All I added was a console.readline so that it would stay open when the answer pops up – Luna Kitten Nov 13 '17 at 01:18