Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

Question regarding C++ and ENUM and SWITCHCASE

OpenStudy (anonymous):

#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; }

OpenStudy (anonymous):

why doesn't this work? i get an error on codeenum=input;

OpenStudy (anonymous):

well after SALE you dont need a comma

OpenStudy (anonymous):

also, you might want a default case

OpenStudy (shadowfiend):

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.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!