I do not understand how to use enumeration types. I understand what they are, but I don't quite get their purpose.
I have made a program that inputs three sides of a triangle and outputs whether or not they are isosceles, scalene, or equilateral. I'm suppose to incorporate the enumeration type somewhere, but don't get where and how to use them. Any help would be appreciated.
#include <iostream>
using namespace std;
enum triangleType {scalene, isosceles, equilateral, noTriangle};
triangleType triangleShape(double x, double y, double z);
void printTriangleShape(triangleType shape);
int main()
{
double x, y, z;
triangleType scalene, isosceles, equilateral, noTriangle;
cout << "Please enter the three sides of a triangle:" << endl;
cout << "Enter side 1: ";
cin >> x;
cout << endl;
cout << "Enter side 2: ";
cin >> y;
cout << endl;
cout << "Enter side 3: ";
cin >> z;
cout << endl;
triangleType t = triangleShape(x, y, z);
printTriangleShape(t);
return 0;
}
triangleType triangleShape(double x, double y, double z)
{
triangleType scalene, isoceles, equilateral, noTriangle;
if (((x+y) > z) && ((x+z) > y) && ((y+z) > x))
{
cout << "You have a triangle!" << endl;
if (x == y && y == z)
return equilateral;
else if (x == y || x == z || y == z)
return isosceles;
else
return scalene;
}
else if ((x+y) <= z || ((x+z) <= y) || ((y+z) <= x))
return noTriangle;
}
void printTriangleShape(triangleType shape)
{
switch (shape)
{
case scalene: cout << "Your triangle is Scalene!" << endl;
break;
case isosceles: cout << "Your triangle is an isosceles!" << endl;
break;
case equilateral: cout << "Your triangle is an equilateral!" << endl;
break;
}
}