help with some errors!

Write a program that when a user enters three numbers, the program will tell the user whether those three numbers can form a triangle.

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
double a,b,c;
cout << "Enter 3 numbers and I will tell you if they make a triangle!" << endl;

cout << "Enter 1st number!" << endl;
cin >> a;
cout << "Enter 2nd number!" << endl;
cin >> b;
cout << "Enter 3rd number!" << endl;
cin >> c;


if (a + b > c, a + c > b, and a + c > b) {


cout << "It's a TRIANGLE!" << endl;
}
else
cout << "NOT a TRIANGLE!";

return 0;
}



I:\Documents and Settings\Waters\Desktop\jodi3\main.cpp||In function 'int main()':|
I:\Documents and Settings\Waters\Desktop\jodi3\main.cpp|19|warning: left-hand operand of comma has no effect|
I:\Documents and Settings\Waters\Desktop\jodi3\main.cpp|19|error: invalid operands of types 'void*' and 'double' to binary 'operator+'|
I:\Documents and Settings\Waters\Desktop\jodi3\main.cpp|19|error: label 'a' used but not defined|
||=== Build finished: 2 errors, 1 warnings ===|
First, let me say that your math may be wrong.
Second, you don't need to #include <cmath> for plus and greater than.
Third, commas don't work like that. You need the if statement to be if (a+b>c&&a+c>b&&b+c>c). && is the "and" operator and means that both requirements must be true.
Thanks!

But now I am running it... and number like 8, 7, and 1... are saying it makes a triangle! *Please excuse me ignorace here... but are we sure those numbers make a triangle... Every numbers I put in are coming up as! It's a Triangle! is my math right?


Thanks so much for your help!!
Check the condition you are testing for. It is wrong.
The second and third are the same condition actually.

If that is changed, everything will work.
Topic archived. No new replies allowed.