Problem in C triangle check

Asked

Viewed 89 times

0

The program aims to identify whether a triangle is equilateral, isosceles, or scalene. But there is an error in the isosceles identification line, where if the user puts equal input values on the first two sides and different on the last, he is not recognized.

Example:

  • measure of lado1: 3;
  • measure of lado2: 4;
  • measure of lado3: 2;

Code:

#include<stdio.h>
int main(){

    int L1,L2,L3;
    int equilatero,isoceles,escaleno;


    printf("media do lado1:");
    scanf("%d",&L1);

    printf("media do lado2:");
    scanf("%d",&L2);

    printf("media do lado3:");
    scanf("%d",&L3);

    equilatero = (L1 == L2)&&(L1 == L3);
    printf("seu triangulo eh equilatero: %d\n",equilatero);

    isoceles = ((L1==L2)||(L1==L3)||(L2==L3))&&((L1!=L2)||(L2=!L3)||(L1=!L3));
    printf("seu triangulo eh isoceles: %d \n",isoceles);

    escaleno = (L1 != L2)&&(L2 != L3)&&(L1 != L3);
    printf("seu triangulo eh escaleno: %d \n",escaleno);

    return 0;
}
  • See if it helps you: http://answall.com/q/56916/101

1 answer

0


Your isosceles check is wrong, so it’s not right, the correct would be:

isoceles = (((L1 == L2) && (L2 != L3)) || ((L2 == L3) && (L3 != L1)) || ((L3 == L1) && (L3 != L2)));

I hope I’ve helped.

  • Thank you very much, it helped, I didn’t quite understand why my check was wrong, but your line works perfectly.

  • Actually your thinking is quite correct, however, you wrote your thinking wrong. In the last two checks, instead of putting != you put =!, and so it didn’t work out well.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.