by Dinesh Thakur Category: Control Structures

An enumerated data type is also an user defined data type. The enum keyword is given before the enumerated data type. A list can tell the compiler which values a given variable can take. Consider the following example:

enum temp{Veryhot, Hot, Medium, Cold};

temp is of enum type and has four members Veryhot, Hot, Medium and Cold. The value 0 is assigned to Veryhot, value 1 is assigned to Hot, 2 is assigned to Medium and so on. The enum specifier allows the user to specify the possible value of the type. If an initial value of -1 is assigned to the first element of the enum type, the subsequent elements are assigned the values 0, 1, 2, etc.

A variable of enum type can be declared as follows:

temp t1;

This indicates that t1 is a variable of type temp which is of enum type.


Write C++ program illustrates the use of enumerated data type.

#include <iostream.h>

enum qlty{excellent, good, average};
struct product
    char prodno[10];
    char prodname[20];
    qlty q1;
 } prod;
void main()
   cout<<"Enter Product Number :";
   cout<<"Enter Product Name :";
   cout<<"Enter quality code for the product.";
   cout<<"\n0 for excellent, 1 for good, 2 for average \n";
   cout<<"\n\nProduct Number :"<<prod.prodno;
   cout<<"\nProduct Name :"<<prod.prodname;
      cout<<"\nQuality Excellent";
   else if(prod.q1==1)
      cout<<"\nQuality Good ";
      cout<<"\nQuality Average ";

enumerated data type

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles