Well this is my first program and it runs well with no bugs =D, but that doesnt do much if the professor doesnt think the code is modular or easy to read so I was wondering if you could give some feedback on this program. It's very simple, user inputs three numbers and it will respond with what type of triangle it is and its area with a loop. I appreciate any and all feedback
Code:#include <stdio.h> #include <conio.h> #include <math.h> int main () { int side1, side2, side3; double S; double Area; do{ printf("\nPlease enter three sides of a triangle.\n"); /* S is the semiperimeter of a triangle which is essential in finding*/ scanf("%d%d%d", &side1, &side2, &side3); /* a consistent area for the program. */ S= (float)(side1+side2+side3)/2; Area = sqrt (S * (S-side1) *(S-side2)*(S-side3)); if (((side1 == side2) && (side2 == side3) && (side1 == side3)) && ((side1 + side2 > side3) && (side2 + side3 > side1) && (side1 + side3 > side2))) /* All sides must be equal */ /* and follow the general laws of a triangle:*/ { /* The sum of any two sides must be greater than the remaining side. */ printf("This triangle's sides are %d,%d,%d and is an Equalateral triangle.\nIts area is %.05f.", side1, side2, side3, Area); } else if (((side1 == side2) || (side2 == side3) || (side1 == side3)) && (side1 + side2 >side3) && (side2 + side3 >side1) && (side1 + side3 > side2)) /* Two sides must be equal */ { printf("This triangle's sides are %d,%d,%d and is an Isosceles triangle.\nIts area is %.05f.", side1, side2, side3, Area); } else if ((side1 != side2) && (side3 != side2)&& (side1 != side3) && (side1 + side2 >side3 && side2 + side3 >side1 && side1 + side3 > side2)) /* None of the sides can be the same */ { printf("This triangle's sides are %d,%d,%d and is an Scalene triangle.\n Its area is %.05f.", side1, side2, side3, Area); } else { printf("%d,%d,%d are not valid sides to a triangle.\n", side1,side2,side3); /* Will end the program once user inputs an incorrect combination of numbers. */ getch(); } }while (side1 + side2 >side3 && side2 + side3 >side1 && side1 + side3 > side2); return 0; getch(); }



1Likes
LinkBack URL
About LinkBacks





.