1
I’m trying to get my program to identify a triangle and tell me if it’s equilateral, isosceles, or scalene. I’m a beginner in the C language, so I created a structure with If/Else to analyze the conditions to identify if the typed value corresponds to a triangle, if yes tell me what type of triangle it corresponds to and if it does not correspond to a triangle say that the data entered do not match.
However my problem is that any value typed the program says that the value does not match a triangle.
I wonder if anyone can help me understand my mistake??
int main () {
//VARIAVEIS
float A = 0;
float B = 0;
float C = 0;
printf ("\nCALCULANDO UM TRIANGULO!\n");
printf ("\nDIGITE OS VALORES DOS CATETOS:\n");
getch();
printf ("\nDIGITE O VALOR DE (A):\n");
scanf("%f", &A);
printf ("\nDIGITE O VALOR DE (B):\n");
scanf("%f", &B);
printf ("\nDIGITE O VALOR DE (C):\n");
scanf("%f", &C);
printf ("\nOS VALORES DIGITADOS: %.2fcm %.2fcm %.2fcm\n", A , B , C);
printf ("\nPRESSIONE ENTER...\n");
getch ();
if ((A + B < C) || (B + C < A) || (A + C < B)) {
printf ("\nVAMOS CALCULAR O TRIANGULO\n");
if ((A == B) && (B == C)) {
printf ("\nTRIANGULO EQUILATERO!\n");
}
else {
if((A == B) || (A == C) || (B == C)) {
printf ("\nTRIANGULO ISOCELES!\n");
}
else {
printf ("\nTRIANGULO ESCALENO!\n");
}
}
}
else {
printf ("\nVALORES NAO CORRESPONDEM A UM TRIANGULO!\n");
}
Your code seems to be incomplete. Confirm how you have it in your editor and how it was here in the question to match.
– Isac
can send the complete code?
– LuisHF
Possible duplicate of My program only runs the first if?
– Leila