Area of a triangle-

Hey guys, im new to the forum/website/c++. Ive been asked to find the area of a triangle, by using the following for formula:

Area=√s(s-a)(s-b)(s-c)

Where: s=(a+b+c)/2

Now im not asking you guys to write me a code or anything, but i was wondering if you could give me any tips on writing it. So far, ive managed to write a program that doesnt use the math.h library, here it is:

#include <iostream>
using namespace std;
int main (void)
{
int base,height,area; // declare variables as int
// Choosing meaningful names!
cout << "enter the base of the triangle in cm: \t"; cin >> base;
cout << "enter the height of the triangle in cm: \t"; cin >> height;
area = (base * height)/2;
cout << "The area of your triangle (cm^2) =" << area << "\n";
return 0;
}

Id like to know how to put this into a Math.h library, because id like to expand my knowledge on c++, so any ideas on where to start?

Thanks :)
Last edited on
There is nothing to use <cmath> here for, if A = a*h/2. If A = √s(s-a)(s-b)(s-c), then you need the sqrt() function. I'm sure you know how to find s(s-a)(s-b)(s-c). Just pass the result to sqrt() and you're done.
This helped me alot thanks navees.
Topic archived. No new replies allowed.