What is error in the code

#include
using namespace std;

int main() {
// your code goes here
int a,b,c;
cin>>a>>b>>c;
if(a+b<c||b+c<a||c+a<b){
cout<<-1<<endl;
}else if(a==b&&b==c){
cout<<1<<endl;
}else if(a==b||b==c||c==a){
cout<<2<<endl;
}else{
cout<<3<<endl;
}
return 0;
}
// this code prints 1 if triangle is equalteral , 2 if triangle is isocles , 3 if scalene and -1 if not a valid trangle

CodeChef: Practical coding for everyone, in case anyone’s wondering.

1 Like

According to the property of the triangle
“The sum of the length of any two sides of a triangle is greater than the length of the third side”.
Therefore the condition needs to be lesser than or equal to instead of just lesser than

if(a+b<=c||b+c<=a||c+a<=b)
cout<<-1<<endl;

Click here to check my accepted solution