Would someone please help me figure out how to get my compiler to return a value of -1 for this function?
#include <iostream>
#include <cmath>
using namespace std;
double TriangleArea( double sideA, double sideB, double sideC )
{
double S, area;
S = (sideA + sideB + sideC) / 2.0;
// Function to calculate the area of a triangle
area = ( S * (S - sideA) * (S - sideB) * (S - sideC) );
if(S > 0)
{
area = sqrt( area );
}
else
{
area = -1;
}
return area;
}
int main()
{
double S, area, sideA, sideB, sideC;
// Enter the sides of the triangle.
cout << "Enter the sides of the triangle: \n";
cin >> sideA >> sideB >> sideC;
// calling back The TriangleArea function
area = TriangleArea( sideA, sideB, sideC );
if(area == -1)
{
cout << "Triangle cannot be formed with given sides" << endl;
}
else
{
cout << "\nArea of triangle = " << TriangleArea( sideA, sideB, sideC ) << endl;
}
return 0;
}