I’m trying to list a vector of ingredients.
the class Ingredient only has 2 members and 2 member functions (except for constructor). it holds a name and a category and it has the functions “getName” that returns the name and “getCategory” that returns category. these ingredients are then stored in a vector – cabinet.
here is the code that SHOULD list the content of cabinet:
for(int i = 0; i < cabinet.size(); i++)
{
cout << cabinet[i].getName();
switch(cabinet[i].getCategory())
{
case 1: cout << "Alcohol" << endl;
break;
case 2: cout << "Liqueur" << endl;
break;
case 3: cout << "Brew" << endl;
break;
case 4: cout << "Non alcohol" << endl;
break;
case 5: cout << "Wine" << endl;
break;
}
}
what I get:
[first ingredient][second ingredient][thrid ingredient]...etc
so, why doesn’t my switch-statement work?
Thanks for the help! I tried adding
default: cout << cabinet[i].getCategory();and found that I accidently stored it as a char. fixed the add-function and now it works.Thanks again for the help!