Using C Define an enumeration type triangleType with values
Using C++
Define an enumeration type triangleType with values EQUILATERAL, RIGHT, ISOSCELES, and SCALENE. Also, declare the variable triangle of type triangleType while defining this type.
Solution
Please find the answer below:
enum triangleType { EQUILATERAL, RIGHT, ISOSCELES, SCALENE };
triangleType triangle = EQUILATERAL;
---------------------------------------------------------------
Here : enum triangleType { EQUILATERAL, RIGHT, ISOSCELES, SCALENE }; will declare an enumeration type called triangleType with its values as : EQUILATERAL, RIGHT, ISOSCELES, and SCALENE.
triangleType triangle = EQUILATERAL; This line declare a variable called triangle as of type triangleType and assigns its a value EQUILATERAL.
Please find below a sample program that shows the value of a triangleType:
#include <iostream>
#include <string>
using namespace std;
enum triangleType { EQUILATERAL, RIGHT, ISOSCELES, SCALENE };
int main()
{
triangleType triangle = ISOSCELES;
cout << \"Value of triangel: \"<< triangle << endl;
}
-----------------
OUTPUT:
Value of triangle: 2
