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; //Answers 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; }



LinkBack URL
About LinkBacks


