how do I use an enum value on a switch statement in C++

后端 未结 8 1301
独厮守ぢ
独厮守ぢ 2020-12-02 20:16

I would like to use an enum value for a switch statement. Is it possible to use the enum values enclosed in \"{}\" as cho

8条回答
  •  失恋的感觉
    2020-12-02 20:39

    i had a similar issue using enum with switch cases later i resolved it on my own....below is the corrected code, perhaps this might help.

         //Menu Chooser Programe using enum
         #include
         using namespace std;
         int main()
         {
            enum level{Novice=1, Easy, Medium, Hard};
            level diffLevel=Novice;
            int i;
            cout<<"\nenter a level: ";
            cin>>i;
            switch(i)
            {
            case Novice: cout<<"\nyou picked Novice\n"; break;
            case Easy: cout<<"\nyou picked Easy\n"; break;
            case Medium: cout<<"\nyou picked Medium\n"; break;
            case Hard: cout<<"\nyou picked Hard\n"; break;
            default: cout<<"\nwrong input!!!\n"; break;
            }
            return 0;
         }
    

提交回复
热议问题