Oh I see what you are doing here but you are getting the input from the user as a string, is it possible to get an input from the user that will accept it as an enum type that I defined?
is it possible to get an input from the user that will accept it as an enum type that I defined?
Unfortunately, enums don't support automatic translation from strings to enum values.
Taking integralfx code, we can change his get_bloodtype_for_str() function to return an enum.
1 2 3 4 5 6 7 8 9
bloodtypes get_bloodtype_for_str (string bl)
{ // Following array MUST match the order of the enum
staticconst string bloodtypes_str[] = { "A", "B", "AB", "O" };
for(size_t i=0; i<sizeof(bloodtypes_str); i++)
if (bl == bloodtypes_str[i])
return (bloodtypes)i;
return (bloodtypes)-1; // No match found
}