1. ## Triangle

Program is supposed to get 3 sides of a tri, list them in nondecreasing order, list the type of triangle. It works like a beauty sometimes, but for others, the second input turns into garbage.

Code:
```//Included Files
#include <iostream>
using namespace std;

//Function Prototypes
bool isTri(float, float, float);
bool isIso(float, float, float);
bool isEqu(float, float, float);
bool isSca(float, float, float);
bool isAcu(float, float, float);
bool isRig(float, float, float);
bool isObt(float, float, float);

//Main Function
int main() {
//Variable Declarations
float a,b,c;
float x,y,z;
//Inputs
cout << " Please enter the triangle lengths: "<<endl;
cout << " Length 1: ";
cin >> a;
cout << " Length 2: ";
cin >> b;
cout << " Length 3: ";
cin >> c;
//Order

if (c>=a && a<=b)
x = a;
if (c>=b && b<=a)
x = b;
if (b>=c && c<=a)
x = c;
if (a<=b && b<=c)
y = b;
if (a<=c && c<=b)
y = c;
if (c<=a && b<=a)
y = a;
if (a>=b && a>=c)
z = a;
if (b>=c && b>=a)
z = b;
if (c>=b && c>=a)
z = c;

cout << "Lengths in nondecreasing order: "<<x<<", "<<y<<", "<<z<<endl;

cout<<"The triangle is: ";
if (isTri(x,y,z))
{
if (isIso(x,y,z))
{
cout << "Isoceles ";
}
if (isEqu(x,y,z))
{
cout << "Equilateral ";
}
if (isSca(x,y,z))
{
cout << "Scalene ";
}
if (isAcu(x,y,z))
{
cout << "Acute ";
}
if (isRig(x,y,z))
{
cout << "Right ";
}
if (isObt(x,y,z))
{
cout << "Obtuse ";
}
}
else
{
cout <<"illegal ";
}
cout<<endl;
return 0; }

//isTriangle

bool isTri(float x,float y,float z)
{
if (x > 0 && ((x + y) > z))
return true;
else
return false;
}

//isIso
bool isIso(float x,float y,float z)
{
if (x == y || y == z)
return true;
else
return false;
}

//isEqu
bool isEqu(float x,float y, float z)
{
if (x == y && y == z)
return true;
else
return false;
}
//isSca
bool isSca(float x,float y, float z)
{
if (x<y && y<z)
return true;
else
return false;
}
//isAcu
bool isAcu(float x,float y, float z)
{
if ((x*x)+(y*y)>(z*z))
return true;
else
return false;
}
//isRig
bool isRig(float x,float y, float z)
{
if ((x*x)+(y*y) == (z*z))
return true;
else
return false;
}
//isObt
bool isObt(float x,float y,float z)
{
if ((x*x)+(y*y) < (z*z))
return true;
else
return false;
}```

2. Originally Posted by howeezy
Program is supposed to get 3 sides of a tri, list them in nondecreasing order, list the type of triangle. It works like a beauty sometimes, but for others, the second input turns into garbage.
So? What is the problem?

3. Originally Posted by howeezy
, but for others, the second input turns into garbage.
that

4. The way you have it setup, x,y and z are not always necessarily set as something in all your if statements, so the memory space is left blank and whatever happened to be there before is used.

You can either initialize them as say 0 or 1 when you declare them, or put in an else statement to initialize them to something else.

But, the method you are using when you are currently getting garbage you will get the wrong answer.

I am not even sure why you are using the if statements to set x,y,z as the side lengths when the user has already input them?

5. The assignment requires me to list them in nondecreasing order.

6. why are they not set??? what am i missing?

7. >> but for others, the second input turns into garbage.

What others? What input do you give? What output do you get?

8. an example is attached