How to sort a Triangle

4

I want to classify a triangle on the sides, and a triangle with all equal sides is called Equilateral, with all sides different from each other called Scalene, and if it has only two equal sides, it is called Isosceles. p>

I tried to do this:

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;
}

At least using the condition if to get an equilateral triangle, but I have not yet been able to get the rest, what will be the way, using conditions if , else if and else

    
asked by anonymous 12.12.2015 / 16:48

1 answer

6

Just do this:

if (a == b && b == c) {
    cout << "Triangulo equilatero." << endl;
}
else if(a == b || b == c){
    cout << "Triangulo isosceles." << endl;
}
else
    cout << "Triangulo escaleno." << endl;

Can you understand why?

Basically the algorithm is as follows:

If the three sides are equal (a = b e b = c) then it is equilateral, otherwise if at least one pair is identical (a = b ou inclusivo b = c) then is isosceles, otherwise is scalene).

    
12.12.2015 / 16:53