123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|514|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> C/C++/C#/Other -> Heron' formula

Mon, 11 Apr 2011, 15:08
killa57
Hi i know im new to this and dont have much posts but im learning trying to home teach my self C#
and i have a problem if this code looks right?
its an application that reads the length of the triangle sides from a user using the herons formula which is s=(a+ b+c) /2.0d;
area= Math.Sqrt(s*(s-a)*(s-b)*(s-c));
in which s represents half of the perimeter of the trangle a,b,c represents the length of the three sides, how do i print the areas to three decimal places? and does the code look good so far?
im using microsoft visual c#2010 express


Mon, 11 Apr 2011, 15:21
Spare
I've had a quick look and your code looks fine to me. You can use string formatting to get the 3 decimals you want:


or


See: msdn.microsoft.com/en-us/library/dwhawy9k.aspx
Mon, 11 Apr 2011, 16:22
killa57
i tried the D3 but i got format error so i tried this and it did its job thanks for the help it gave me an idea on how to do it