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

Apr 1, 2013 at 1:03am
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;
}
Apr 1, 2013 at 1:14am
You don't need to specify a condition for the else statement.
Apr 1, 2013 at 1:14am
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.
Apr 1, 2013 at 1:25am
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.
Apr 1, 2013 at 2:05am
You could simply delete the line which produces that output. Or comment it out with //
Apr 1, 2013 at 2:16am
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.

Apr 1, 2013 at 2:37am
Yes, but we don't normally do homework for people :)
Topic archived. No new replies allowed.