Created
April 12, 2020 08:18
-
-
Save webber2408/bdf486239cdc3522d3784918d840a178 to your computer and use it in GitHub Desktop.
C++ Enumerations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
enum Direction {North, South, East, West} dir; | |
enum Gender {Male, Female}; | |
int main(){ | |
//Example 1 | |
dir = East; | |
cout<<"Currenct Direction: "<<dir<<endl; | |
//dir = NorthEast; //Error: identifier "NorthEast" is undefined | |
for(int i= North; i<= West; i++){ | |
cout<<i<<" "; | |
} | |
cout<<endl; | |
//Example 2 | |
Gender g = Male; | |
cout<<"Gender: "<<g<<endl; | |
switch (g) | |
{ | |
case Male: | |
cout<<"Male it is!"<<endl; | |
break; | |
case Female: | |
cout<<"Female it is!"<<endl; | |
break; | |
} | |
return 0; | |
} | |
/* | |
Output: | |
Currenct Direction: 2 | |
0 1 2 3 | |
Gender: 0 | |
Male it is! | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment