0
string CTriangle::TriangleType(string TypeOfTriangle)
{
        if ( ValidTriangle() )
        {
		if ( SideA == SideB && SideA == SideC && SideB == SideC )
		{
			TypeOfTriangle = "Equilateral Triangle";
		}
		if ( int(AngleA()) == 90 || int(AngleB()) == 90 || int(AngleC()) == 90 )
		{
			TypeOfTriangle = "Right-Angled Triangle";
		}
		if ( SideA == SideB || SideA == SideC || SideB == SideC )
		{
			TypeOfTriangle = "Isoscules Triangle";
		}
		if ( (SideA != SideB && SideA != SideC && SideB != SideC) && ( AngleA() < 90.0 && AngleB() < 90.0 && AngleC() < 90.0 ) )
		{
			TypeOfTriangle = "Scalene/Acute Triangle";
		}
		/*
		if ( AngleA() < 90.0 && AngleB() < 90.0 && AngleC() < 90.0 )
		{
			TypeOfTriangle = "Acute-Angled Triangle";
		}
		*/
		if ( (AngleA() > 90.0 || AngleB() > 90.0 || AngleC() > 90.0) && (SideA != SideB && SideA != SideC && SideB != SideC) )
		{
			TypeOfTriangle = "Obtuse/Scalene Triangle";
		}
		if ( AngleA() > 90.0 || AngleB() > 90.0 || AngleC() > 90.0 ) 
		{
			TypeOfTriangle = "Obtuse Triangle";
		}
		return TypeOfTriangle;
	}
	else
		exit(1);
}

how do I compare AngleA() with 90? I cast int before AngleA() (its return value is double) but if I put a (3,4,5) triangle, it goes down to

if ( (SideA != SideB && SideA != SideC && SideB != SideC) && ( AngleA() < 90.0 && AngleB() < 90.0 && AngleC() < 90.0 ) )
		{
			TypeOfTriangle = "Scalene/Acute Triangle";
		}

i have all the values computed and on the command prompt shows AngleC = 90.000, (setprecision(3)), need help please

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by nbaztec
0

You narrowing the double really beats the purpose of the program. Note that a triangles having 90.5 degree angle can never be right-angled, yet your program will show it to be right-angled.
While comparing int with double you should try typecasting int to double. Some compilers will do that by default.
If I miss the point, then it's because I don't understand your problem.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.