Question regarding C++ and ENUM and SWITCHCASE
#include <iostream> using namespace std; enum _codeenum{ ADD, DELETE, RESTOCK, DISPOSE, SALE, }; int main () { string input; enum _codeenum codeenum; cin>>input; codeenum=input; switch(codeenum){ case ADD:{ cout<<"0"<<endl; break; } case DELETE:{ cout<<"1"<<endl; break; } case RESTOCK:{ cout<<"2"<<endl; break; } case DISPOSE:{ cout<<"3"<<endl; break; } case SALE:{ cout<<"4"<<endl; break; }; } return 0; }
why doesn't this work? i get an error on codeenum=input;
well after SALE you dont need a comma
also, you might want a default case
codeenum is an enum, therefore a glorified int. Input, on the other hand, is a String. Strings cannot be converted to enums automatically, you're going to have to do a string of ifs to assign the enum properly based on what the user typed in.
Join our real-time social learning platform and learn together with your friends!