I am trying to convert an Enum type called:
enum Category{unknown = -1, meat, poultry, seasfood, diary, vegetable, fruit, grain,sweet};
And a struct Food that contains array Category category.
The user is given numbers to enter for the Category types, ie: 0 = meat, etc.
My program can take that in and output the number for the category. But I need to convert that number so that category output reads the name of the category instead of the number of the category.
I tried doing a static_cast<Category>(temp) to convert the input, but my compiler gave a convertion error. I wrote a function to convertEnum using switches:
void convertEnum(Food foodItem[],Category category)
{
int i = 0;
switch (category)
{
case 0: strcpy(foodItem[i].category, "meat");
break;
case 1: strcpy(foodItem[i].category, "poultry");
break;
case 2: strcpy(foodItem[i].category, "seafood");
break;
case 3: strcpy(foodItem[i].category, "dairy");
break;
case 4: strcpy(foodItem[i].category, "vegetable");
break;
case 5: strcpy(foodItem[i].category, "fruit");
break;
case 6: strcpy(foodItem[i].category, "grain");
break;
case 7: strcpy(foodItem[i].category, "sweet");
}
And I get error codes for unable to convert....
Any help would be appreciated. If my function to convertEnum is correct, would the best place to call the function be before the input of category or during the output?
My project was "done" until I had to convert the category number. :(