Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.
Ask a Question
Ask a Question
I cannot figure out how to get my program to return a value of -1.
Would someone please help me figure out how to get my compiler to return a value of -1 for this function?
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 );
area = -1;
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;
cout << "\nArea of triangle = " << TriangleArea( sideA, sideB, sideC ) << endl;
closed with the note:
figured the biotch out
Obviously putting in junk values will do it.
Enter the sides of the triangle:
Triangle cannot be formed with given sides
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
To avoid this verification in future, please
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
Snow Theme by