How to use enumeration types in C++?
- by Sagistic
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};
void triangleShape(double x, double y, double z);
int main()
{
double x, y, z;
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;
triangleShape(x, y, z);
return 0;
}
void triangleShape(double x, double y, double z)
{
if (((x+y) > z) && ((x+z) > y) && ((y+z) > x))
{
cout << "You have a triangle!" << endl;
if (x == y && y == z)
cout << "Your triangle is an equilateral" << endl;
else if (x == y || x == z || y == z)
cout << "Your triangle is an isosceles" << endl;
else
cout << "Your triangle is a scalene" << endl;
}
else if ((x+y) <= z || ((x+z) <= y) || ((y+z) <= x))
cout << "You do not have a triangle." << endl;
}