### Stumped by what this means

I have been asked to write a program(in C++) which, given three values representing the sides of a triangle prints:
0 if the values cannot be the sides of any triangle. This is so if any value is negative or zero, or if any length is greater than the sum of the other two.
1 If the triangle is equilateral.
2 If the triangle is isosceles
3 if the triangle is scalene.

**********************HERE IS MY PROGRAM*********************

 ``123456789101112131415161718192021222324`` ``````#include #include using namespace std; int main(){ double a,b,c; cout<<"enter 3 values of your triangle"<< endl; cin>>a>>b>>c; if( (a==b&& a!=c) || (a==c && a!=b) || (b==c && b!=a) ) { cout<< " This triangle is Isosceles"<

I have WRITTEN almost all of the program and it works! however I do not understand how to implement this part: "0 if the values cannot be the sides of any triangle. This is so if any value is negative or zero, or if any length is greater than the sum of the other two." Can someone kindly tell me what does this means?
Check to make sure that non of the values entered are negative or zero. This should be easy enough. If a side has a length of zero or less then it can't possibly form a triangle.

Then check each side to make sure it's length isn't greater than the sum of the other two. Again, if the sum of the other two side is less than the length of one side, they can't logically form a triangle.

 ``12`` ``````if( c > ( a + b ) ) cout << "Cannot be a triangle\n";``````

You'll need to add or statements for the other two sides.
Last edited on
So you are basically saying this:

 ``12345678`` `````` /* If a or b or c is less than or equal to 0 then print " cannot be a triangle" if c is greater than the sum of a and b then print "cannot be a triangle" */ if( c > ( a + b ) && a<=0|| b<=0 || c<=0) cout << "Cannot be a triangle\n"; ``````
You cant have negative sides or a side missing (a side with 0 length). Also, you cant have a triangle with sides 100,1, and 5 because 1+5>100, meaning the longest side is stretched out so far, that the other sides cannot connect to it. This results in an open figure. Therefore, you must change your program like this:

 ``1234567891011121314151617181920212223242526272829303132333435363738`` ``````#include int main() { double a,b,c; std::cout<<"This program finds out if a triangle is scalene, isosceles, or equilateral."<>a; std::cout<<"B? "; std::cin>>b; std::cout<<"C? "; std::cin>>c; if(((a+b)
Last edited on
Oh now I see. thanks for the clarification
Topic archived. No new replies allowed.