i am having some problems writing down the source code that can figure out all the types of triangle(isosceles,scalene,equilateral & right trianlge).
here are the things that i need to do:

  1. to determine if the entered sides form a valid triangle or not.
  2. to determine the types of triangle.

and below is my work that is only half done...

#include <iostream>
#include <iomanip>

using namespace std;

int main ()

    double a, b, c;
    char sideA, sideB, sideC;

        cout<<"\nEnter the length of "<<sideA<<":\n";

        cout<<"\nEnter the length of "<<sideB<<":\n";

        cout<<"\nEnter the length of "<<sideC<<":\n";

        cout<<"\nIt is not a  Triangle.<<\n";

        else if (sideA==sideB&&sideB==sideC)
            cout<<"\nIt is an equilateral triangle.\n";

        else if (sideA==sideB||sideB==sideC||sideA==sideC)
            cout<<"\nIt is an isoceles triangle.\n";

    if (((sideA*sideA)+(sideB*sideB)==(sideC*sideC))||((sideA*sideA)+(sideC*sideC)==(sideB*sideB))||((sideB*sideB)+(sideC*sideC)==(sideA*sideA)))
        cout<<"\nIt is a right triangle.\n";
        cout<<"\nIt is not a right triangle.\n";

            cout<<"\nIt is a scalane triangle.\n";


can someone pls help me out...

Now I'm assuming you want to sorta tidy this up, so that's what I'm gonna try to help with.

First, I'd suggest doing something like, if it's not a triangle, stop. There's no point going through the rest of the if statements if it's not a triangle cause it will just mess up your output. So just do something like:

if (/*this is NOT a triangle*/)
   { /*print out "This is not a triangle"*/ }
  { /* do the rest of my code to determine the type of triangle 
     code goes here */

Second, if I were writing this, I would try breaking it up into nested if statements so that you can limit the amount of work. Just speaking in English, scalene has all different sides, an isosceles triangle has two equal sides and an equilateral has three equal sides.

If you look at the lengths, and two sides (call them a and b) are equal, you know off the bat that it can't be scalene. Going along with that, it means that this triangle is either isosceles or equilateral but we won't know until we look at the last side. When you look at side c, you either see it is equal to b or not, if so, it's equilateral, if not, isosceles (since we already said two sides were equal). Now we just need to figure where the scalene case goes. Well, if no two sides were equal, which was the statement we were checking above, that means that what's left is the scalene case.

In essence, I just limited most of your code to something like this.

if ( /* check if two sides are equal*/)
   { if ( /* see if third side is  equal */ )
        { /* print equilateral */ }
        { /* print isosceles */ }
else // no two sides were equal, thus
   { /* print scalene */ }

Then, as far as what the code you've given us says, you just have to check if it's a right triangle as well. As long as it isn't an equilateral triangle, it can be a right as well. So, I would just take your if statement and just paste it after the code I have above.

if ( /* check against formula a^2 + b^2 == c^2 in all three cases*/)
    { /* print Right triangle */ }
    { /* not a right triangle*/ }

Now, really if you just put my pieces together and then fill in the comment tags with actual coding (which you already supplied), you should basically be done.

Also, random fact, if it's not a right triangle, it's sometimes called an oblique triangle (meaning a triangle that doesn't have an internal angle of 90 degrees).

I hope this helped.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.