-
Notifications
You must be signed in to change notification settings - Fork 11
/
enum.cpp
38 lines (34 loc) · 1.02 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
#include <iostream>
#include <stdlib.h>
using namespace std;
enum Company{
Google = 1, Facebook, Twitter, Snapdeal, Microsoft //Google is initialized with value 1. First value, unless stated, takes value as 0.
};
int main(int argc, char const *argv[]){
int choice;
do {
cout << "Please enter a choice : ";
cin >> choice;
switch(choice){
case Google:
cout << "You have chosen Google.";
break;
case Facebook:
cout << "You have chosen Facebook.";
break;
case Twitter:
cout << "You have chosen Twitter.";
break;
case Snapdeal:
cout << "You have chosen Snapdeal.";
break;
case Microsoft:
cout << "You have chosen Microsoft.";
break;
default: //default is used when none of cases mentioned above is hitted.
cerr << "ERROR: Please enter a valid choice. Enter again.\n"; //cerr is used to output an error message only. It works same as cout.
break;
}
}while (choice < 0 || choice > 5);
return 0;
}