4
I want to classify a triangle as to the sides, being that a triangle with all equal sides is designated Equilateral, with all different sides being designated Escaleno and if it has only two equal sides, it is called Isosceles.
I tried to do it this way:
void HeaderClass::ClassificarUmTriangulo() {
int x1, x2, x3, y1, y2, y3, a, b, c;
cout << "Coordenadas do ponto1 (x): ";
cin >> x1;
cout << "Coordenadas do ponto1 (y): ";
cin >> y1;
cout << "Coordenadas do ponto2 (x): ";
cin >> x2;
cout << "Coordenadas do ponto2 (y): ";
cin >> y2;
cout << "Coordenadas do ponto3 (x): ";
cin >> x3;
cout << "Coordenadas do ponto3 (y): ";
cin >> y3;
Sleep(SLEEP_1);
a = sqrt(((x2 - x1)*(x2 - x1)) + ((y2 - y1)*(y2 - y1)));
b = sqrt(((x3 - x2)*(x3 - x2)) + ((y3 - y2)*(y3 - y2)));
c = sqrt(((x1 - x3)*(x1 - x3)) + ((y1 - y3)*(y1 - y3)));
if (a == b && b == c) {
system("cls");
cout << "Triangulo equilatero." << endl;
}
Managing to at least use the condition if
to get a triangle equilatro, but still not able to get the remaining ones, what will be the way to, using the conditions if
, else if
and else
But, that
else if(a == b || b == c)
won’t cause bugs or anything like that ?– André
No. I’ll edit the question.
– Alexandre Cartaxo
I was thinking of something more complicated, and it turned out to be that simple. I thought something like this:
else if( a == b && *a não é igual a c etc..)
– André
@André I think you need to take a closer look at the structure
if (condição_1) (...) else if (condição_2) (...) else (...)
.– Alexandre Cartaxo