### Help me with some homework due in an hour

Hey, Here's my computer science homework. You are supposed to be able to input three sides of a triangle, and it should give you the kind of triangle it is (if it is one), area, sides, and perimeter. I'm not really sure how to use the if, if else, and else statements. Could someone help me fix it to display the correct triangles when i input my numbers?

Thanks,
Wesley
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051`` `````` #include #include using namespace std; int main() { int perimeter, sideA, sideB, sideC, area, s; cout <<"Enter the first side of the triangle> "; cin >> sideA; cout <<"Enter the second side of the triangle> "; cin >> sideB; cout <<"Enter the last side of the triangle> "; cin >> sideC; perimeter = sideA + sideB + sideC; s = (sideA+sideB+sideC) /2; area = sqrt ( s * (s - sideA) * (s - sideB) * (s - sideC) ); if ((sideA*sideA) + (sideB*sideB) == (sideC*sideC) || (sideB*sideB) + (sideC*sideC) == (sideA*sideA) || (sideC*sideC) + (sideA*sideA) == (sideB*sideB)); { cout<<"The numbers you have input make a right triangle> " << endl; cout<<"Sides: " << sideA << sideB << sideC << endl; cout<<"Perimeter: " << perimeter << endl; cout<<"Area: " << area << endl; } if ((sideA==sideB) || (sideB==sideC) || (sideA==sideC)); { cout<<"The numbers you have input make an isosceles triangle> " << endl; cout<<"Sides: " << sideA << sideB << sideC << endl; cout<<"Perimeter: " << perimeter << endl; cout<<"Area: " << area << endl; } if (( sideA == sideB && sideB == sideC )); { cout<<"The numbers you have input make an equilateral triangle> " << endl; cout<<"Sides: " << sideA << sideB << sideC << endl; cout<<"Perimeter: " << perimeter << endl; cout<<"Area: " << area << endl; } if ((sideA!=sideB) || (sideB!=sideC)); { cout<<"The numbers you have input make a scalene triangle> " << endl; cout<<"Sides: " << sideA << sideB << sideC << endl; cout<<"Perimeter: " << perimeter << endl; cout<<"Area: " << area << endl; } return 0; }``````
I know it's probably too late, but let this be a lesson to you: Don't wait till the hour before to ask for homework help.

You needed to remove those semi-colon's from the end of your if conditionals...Otherwise, it's just a statement, and then the rest of your program, from start to finish, are all just statements.

Also, I changed the if, to else if. It actually works with either if or else if, now that I check it again...Was definitely the semi-colon's!

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051`` ``````#include #include using namespace std; int main() { int perimeter, sideA, sideB, sideC, area, s; cout <<"Enter the first side of the triangle> "; cin >> sideA; cout <<"Enter the second side of the triangle> "; cin >> sideB; cout <<"Enter the last side of the triangle> "; cin >> sideC; perimeter = sideA + sideB + sideC; s = (sideA+sideB+sideC) /2; area = sqrt ( s * (s - sideA) * (s - sideB) * (s - sideC) ); if ((sideA*sideA) + (sideB*sideB) == (sideC*sideC) || (sideB*sideB) + (sideC*sideC) == (sideA*sideA) || (sideC*sideC) + (sideA*sideA) == (sideB*sideB)) { cout<<"The numbers you have input make a right triangle> " << endl; cout<<"Sides: " << sideA << sideB << sideC << endl; cout<<"Perimeter: " << perimeter << endl; cout<<"Area: " << area << endl; } else if ((sideA==sideB) || (sideB==sideC) || (sideA==sideC)) { cout<<"The numbers you have input make an isosceles triangle> " << endl; cout<<"Sides: " << sideA << sideB << sideC << endl; cout<<"Perimeter: " << perimeter << endl; cout<<"Area: " << area << endl; } else if (( sideA == sideB && sideB == sideC )) { cout<<"The numbers you have input make an equilateral triangle> " << endl; cout<<"Sides: " << sideA << sideB << sideC << endl; cout<<"Perimeter: " << perimeter << endl; cout<<"Area: " << area << endl; } else if ((sideA!=sideB) || (sideB!=sideC)) { cout<<"The numbers you have input make a scalene triangle> " << endl; cout<<"Sides: " << sideA << sideB << sideC << endl; cout<<"Perimeter: " << perimeter << endl; cout<<"Area: " << area << endl; } return 0; }``````
Last edited on
Topic archived. No new replies allowed.