# I cannot figure out how to get my program to return a value of -1.

closed Mar 7, 2020
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;
}
closed with the note: figured the biotch out

–1 vote
answered Mar 7, 2020 by (240 points)
Obviously putting in junk values will do it.

E.g.

Enter the sides of the triangle:

-2

-4

0

Triangle cannot be formed with given sides