can someone check this code and tell me what is wrong with it

closed account (oNRiz8AR)
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()

{
double S, A, B, C;
A = 1;
B = 2;
C = 6;
S = (A+B+C)/2;

cout << "The Area of the triangle is = " << sqrt(S*(S-A)*(S-B)*(S-C)) << endl;

if (sqrt(S*(S-A)*(S-B)*(S-C)) > 0)
{
cout << "THE TRIANGLE EXISTS" << endl;
}
else (sqrt(S*(S-A)*(S-B)*(S-C)) <= 0)
{
cout << "THIS TRIANGLE DOES NOT EXIST";
}

return 0;
}
You don't need to specify a condition for the else statement.
make the else statement either
1
2
3
4
else if (sqrt(S*(S-A)*(S-B)*(S-C)) <= 0)
{
	cout << "THIS TRIANGLE DOES NOT EXIST";
}

or
1
2
3
4
else 
{
	cout << "THIS TRIANGLE DOES NOT EXIST";
}

This is because when you started an if statement. After that you said else, which means all other cases that are different than the initial if conditions. So you wouldn't say else (sqrt(S*(S-A)*(S-B)*(S-C)) <= 0), you would need to say else IF and then the condition.
closed account (oNRiz8AR)
When I compile, it runs... but the output looks like this:

The Area of this triangle is = nan
THIS TRIANGLE DOES NOT EXIST.

I do not really know, but is there a way that the output only shows:

THIS TRIANGLE DOES NOT EXIST

Not the other line.
You could simply delete the line which produces that output. Or comment it out with //
closed account (oNRiz8AR)
Thank so much for helping out... y'all were very helpful.
Again... Thank you so much! Un millon de gracias. Grazie per tutto.

Yes, but we don't normally do homework for people :)
Topic archived. No new replies allowed.