How to use if-else sets correctly in C?

1

I'm having a problem with this code in DevC ++, as I see the part of the if-else conditions is perfectly indented and organized (all if has its else and its keys). The error is in the last else , but I do not know how to solve it, because I need this condition.

The aim of the program is to classify the three values inserted into a triangle, and to form, to classify in equilateral, isosceles and scalene. However, if they do not form a triangle, they send out a message. This is where the problem is, because the program does not compile if I enter this last condition.

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, 
system("pause") or input loop */

int main(int argc, char *argv[]) {

int a, b, c;
char equi[] = "Triangulo equilatero.";
char isos[] = "Triangulo isosceles." ; 
char esc [] = "Triangulo escaleno."  ;

scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);

if ((a > 0) && (b > 0) && (c > 0) && (a<(b+c)) && (b<(a+c)) && (c<(a+b)))
{
    if( (a==b) && (b==c) )
    {
        printf("%s", equi);
    }else{
        if( (a==b) || (b==c) || (c==a) )
        {
            printf("%s", isos);
        }else{
            printf("%s", esc);
        }   
    }

/* O problema está aqui neste ultimo else abaixo, pois se eu retirar essa 
linha o programa compila. No entanto se eu deixar, dá um erro "id returned 1 
exit status".*/

}else{
    print("Nao e possivel formar um triangulo."); 
} 
return 0;
}
    
asked by anonymous 26.10.2018 / 03:57

1 answer

4

It is not perfect indented and is not well organized, is not so easy to read and this is a hindrance. There is a typo where it has print() when in fact it should be printf() . Here's how easy it is to follow the code:

#include <stdio.h>
int main() {
    int a, b, c;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    if (a > 0 && b > 0 && c > 0 && a < b + c && b < a + c && c < a + b) {
        if (a == b && b == c) printf("Triangulo equilatero.");
        else printf((a == b || b == c || c == a) ? "Triangulo isosceles." : "Triangulo escaleno.");
    } else printf("Nao e possivel formar um triangulo."); 
}

See running on ideone . And in Coding Ground . Also I put it in GitHub for future reference .

    
26.10.2018 / 04:24