int main(void) { printf("triangle validation.\n"); printf("first side: "); float side_a = GetFloat(); printf("second side: "); float side_b = GetFloat(); printf("third side: "); float side_c = GetFloat(); bool validation = valid_triangle(side_a, side_b, side_c); if(validation == true) printf("valid triangle.\n"); else printf("invalid triangle.\n"); return 0; }
/* main function */ int main(void){ /* variable declaration */ double side1 = 0.0; double side2 = 0.0; double side3 = 0.0; double area = 0.0; /* accept sides from the user */ printf("Please enter the first side of the triangle: "); scanf("%lf", &side1); printf("Please enter the second side of the triangle: "); scanf("%lf", &side2); printf("Please enter the third side of the triangle: "); scanf("%lf", &side3); /* proceed with the main program objective */ /* use if and else to branch out first the validity of the triangle */ /* then the shape, and check if the triangle is also isoceles */ /* 0 is false, 1 is true */ /* calculate the area of the triangle */ area = area_of_triangle(side1, side2, side3); /* this is valid */ if (valid_triangle(side1, side2, side3) == 1){ //equilateral triangles are never isoceles if (equilateral_triangle(side1, side2, side3) == 1){ printf("\nEquilateral!\n"); } //right triangle else if (right_triangle(side1, side2, side3)== 1){ //check if triangle is isoceles also if (isoceles_triangle(side1, side2, side3) == 1){ printf("\nIsoceles right triangle!\n"); } else { printf("\nRight triangle!\n"); } } //obtuse triangle else if (obtuse_triangle(side1, side2, side3) == 1){ //check if triangle is isoceles also if (isoceles_triangle(side1, side2, side3) == 1){ printf("\nIsoceles obtuse triangle!\n"); } else { printf("\nObtuse triangle!\n"); } } //acute triangle else if (acute_triangle(side1, side2, side3) == 1){ //check if triangle is isoceles also if (isoceles_triangle(side1, side2, side3) == 1){ printf("\nIsoceles acute triangle!\n"); } else { printf("\nAcute triangle!\n"); } } //print out the area of the triangle after determining the shape printf("The area of the triangle is: %.2f\n", area); } //this is invalid else { printf("\nThe triangle is invalid because the length of one side is greater than or equal to the sum of the lengths of the other two sides\n"); } return (0); }