-
Notifications
You must be signed in to change notification settings - Fork 6
/
enum.cpp
72 lines (63 loc) · 1.05 KB
/
enum.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
using namespace std;
enum weekDays {
mon=1,
tue,
wed,
thu,
fri,
sat,
sun
};
enum months {
jan=1,
feb,
mar,
apr,
may,
jun,
jul,
aug,
sep,
oct,
nov,
decm
};
int main(){
//enum example 1: Using enum with switch case
int num;
cout << "Enter a number between 1 to 7 : ";
cin >> num;
switch(num) {
case mon:
cout << num << "represents Monday";
break;
case tue:
cout << num << "represents Tuesday";
break;
case wed:
cout << num << "represents Wednesday";
break;
case thu:
cout << num << "represents Thursday";
break;
case fri:
cout << num << "represents Friday";
break;
case sat:
cout << num << "represents Saturday";
break;
case sun:
cout << num << "represents Sunday";
break;
default:
cout << "Oops..Invalid Choice !!";
break;
}
//enum example 2
cout << "\n\nAssigned values to enum months: \n";
for (int i=jan; i<=decm; i++) {
cout << i << " ";
}
return 0;
}