1
I have a problem with this code in Devc++, because in my view the conditions part if-else
is perfectly indented and organized (all if
possesses its else
and your keys). The error is in the last else
, but I don’t know how to fix it, because I need this condition.
The objective of the program is to classify the 3 values inserted in a triangle, and to form, classify in equilateral, isosceles and scalene. However, if you do not form a triangle, send a message. This is where the problem lies, because the program does not compile if I insert 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;
}
One tip I’d give you is to use Else if (){} for better code performance.
– Renan