0

Data Tayp

what is the data type "enum" what it do ?

27th Nov 2016, 2:57 PM
Muntaser Abukadeja
Muntaser Abukadeja - avatar
1 Answer
+ 3
An enum (or enumeration) allows you to define your own data type. enum color { RED, GREEN, BLUE }; int main() { color car = RED; switch (car) { case RED: cout << "Car is red"; break; case GREEN: cout << "Car is green"; break; case BLUE: cout << "Car is blue"; break; } } This short little program gives you a good idea of what an enumeration can do. In a more real-world situation, you may have an enumeration for "gamestate" in a game, and you could have values such as RUNNING, PAUSE, QUIT etc. It just makes it a LOT easier than using something like int 1, 2 and 3, which can get confusing.
27th Nov 2016, 3:06 PM
Cohen Creber
Cohen Creber - avatar