Originally Posted by

**anduril462**
Please post your new code. Also, you could "flatten" the structure manasij7479 suggested:

Code:

if triangle is invalid
print error
else if equilateral
...
else if isosceles
...
else
// scalene

Your first call to getch should probably

*not* be inside the else clause, otherwise it wont always be executed (i.e. why would you only want to call getch when they entered an invalid input). Your last call to getch is after the return 0; in main, so it will never get executed. Either remove it or switch the two lines.

Lastly, as others pointed out, S is poorly names. So much so that you need a comment to explain that S is the semiperimeter. Just call it semiperimeter and be done with it.

Here is the new code I have, I rewrote it..but now the weirdest thing..the math for my areas is wrong. For example..sides 3,4,5 should have area 6 but now im getting 7.2 -_-.

Code:

#include <stdio.h>
#include <conio.h>
#include <math.h>
int main ()
{
int side1, side2, side3;
double semiperimeter, area;
do
{ printf("\n Please enter three sides to a triangle. \n");
scanf("%d%d%d", &side1, &side2, &side3);
semiperimeter = (double)(side1 + side2 + side3)/2;
area = sqrt(semiperimeter * (semiperimeter - side1) * (semiperimeter - side1) * (semiperimeter - side3));
if (side1 + side2 > side3 && side2 + side3 > side1 && side1 + side3 > side2)
{ if ((side1 == side2) && (side2 == side3))
printf("This triangles sides are %d,%d,%d and is an equalateral triangles.\nIts area is %.05f.\n", side1, side2, side3, area);
else if ((side1 == side2) || (side2 == side3) || (side1 == side3))
printf("This triangles sides are %d,%d,%d and is an Isosceles triangle.\nIts area is %.05f.\n", side1, side2, side2, area);
else
printf("This triangles sides are %d,%d,%d and is a Scalene triangle.\nIts area is %.05f.\n", side1, side2, side3, area);
}
else
printf("%d,%d,%d are not valid sides to a triangle.\n", side1,side2,side3);
}while ((side1 + side2 >side3) && (side2 + side3 >side1) && (side1 + side3 > side2));
getch();
return 0;
}