1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#include <iostream>
#include <string>
enum tri {scalene, isosceles, equilateral,noTriangle};
tri id (int a, int b, int c);
void order(int &a, int &b);
std::string readTri (tri ABC);
int main ()
{
int a, b, c;
std::cout << " Enter the length of sides of an triangle: " << "\n";
std::cout << " Enter the first side: " << "\n";
std::cin >> a;
std::cout << " Enter the second side: " << "\n";
std::cin >> b;
std::cout << " Enter the third side: " << "\n";
std::cin >> c;
order(b,c);
order(a,b);
tri ABC = id(a,b,c);
std::cout << " This triangle is a/an " << readTri(ABC) ~<<~ " triangle." << "\n";
}
void order(int &a, int &b)
{
int x;
if (a > b)
{
x = a;
a = b;
b = x;
}
}
tri id (int a, int b, int c)
{
if( a + b < c)
{
return noTriangle;
}
else if( a == b || a == c || b == c)
{
if( a == b && b == c)
{
return isosceles;
}
return equilateral;
}
else
{
return scalene;
}
}
std::string readTri (tri ABC)
{
std::string str;
switch(ABC)
{
case 0:
{
str = "scalene";
break;
}
case 1:
{
str = "isosceles";
break;
}
case 2:
{
str = "equilateral";
break;
}
case 3:
{
str = "noTriangle";
break;
}
}
return str;
~}~
|