void createRecipe(vector<Recipe>& recipe, vector<Ingredient>& ingredients)
{
Recipe* newRecipe = new Recipe;
vector<Ingredient> recipeSpecificIngredients;
vector<double> percent;
double percentage;
char nameOf[80];
int ingNum, ingCount = 0;
double amount;
cout << "Enter the name of the recipe: "; cin.getline(nameOf,80); cout << endl;
cout << "Pick an ingredient" << endl;
for(size_t y = 0; y < ingredients.size(); y++)
{
cout << y << ". " << ingredients[y].name << " $" << ingredients[y].priceML << " " << ingredients[y].weight << "g/ml" << endl;
}
cout << "Enter the number of the ingredient you'd like to add: "; cin >> ingNum; cout << endl;
recipeSpecificIngredients.push_back(ingredients[ingNum]);
cout << "Enter the percentage of this ingredient: "; cin >> percentage; cout << endl;
percent.push_back(percentage);
int* choice = new int(0);
cout << "1. Enter another ingredient" << endl
<< "2. Done with ingredients" << endl;
cin >> *choice;
while(*choice == 1)
{
cout << "Enter the number of the ingredient you'd like to add: "; cin >> ingNum; cout << endl;
recipeSpecificIngredients.push_back(ingredients[ingNum]);
cout << "Enter the percentage of this ingredient: "; cin >> percentage; cout << endl;
percent.push_back(percentage);
cout << "1. Enter another ingredient" << endl
<< "2. Done with ingredients" << endl;
cin >> *choice;
}
cout << "How much of this Recipe would you like to make: "; cin >> amount; cout << endl;
for(size_t y = 0; y < recipeSpecificIngredients.size(); y++)
{
newRecipe->ingredients[y] = recipeSpecificIngredients[y];
newRecipe->percentIngredient[y] = percent[y];
newRecipe->amountML[y] = (percent[y] * amount);
newRecipe->pricePer[y] = recipeSpecificIngredients[y].priceML * newRecipe->amountML[y];
newRecipe->amountGM[y] = recipeSpecificIngredients[y].weight * newRecipe->amountML[y];
}
newRecipe->amountToMake = amount;
recipe.push_back(*newRecipe);
}
void editIngredient(vector<Ingredient>& ingredient, int ingNum)
{
int choice, iChoice;
Ingredient tempIngredient;
double weight,
price,
amount,
cost;
char newName[80];
cout << "Enter your choice to perform the appropriate action" << endl;
cout << "1. Change an ingredient's name" << endl
<< "2. Remove ingredient" << endl
<< "3. Change an ingredient's weight" << endl
<< "4. change an ingredient's cost" << endl
<< "5. Return to previous menu" << endl;
cin >> choice; cout << endl;
while(choice > 5 || choice < 1)
{
cout << "You've entered an invalid choice, try again." << endl;
cin >> choice;
}
while(choice != 5)
{
if(choice == 1)
{
cout << "Enter the new name for the ingredient: "; cin.getline(newName, 80); cout << endl;
strcpy(ingredient[ingNum].name, newName);
}
if(choice == 2)
{
vector<Ingredient>* swapList = new vector<Ingredient>;
for(size_t x = 0; x < sizeof(ingredient); x++)
{
if(x != ingNum)
swapList->push_back(ingredient[x]);
}
ingredient = *swapList;
}
if(choice == 3)
{
cout << "Enter the new weight: "; cin >> weight; cout << endl;
ingredient[ingNum].weight = weight;
}
if(choice == 4)
{
cout << "Enter the amount of liquid purchased: "; cin >> amount; cout << endl;
cout << "Enter the cost of the liquid: "; cin >> cost; cout << endl;
cout << "The price/ml of the flavoring is: " << (cost/amount) << endl;
ingredient[ingNum].priceML = (cost/amount);
}
displayIngredient(ingredient[ingNum]);
}
}
void createIngredient(vector<Ingredient>& ingredient)
{
char name[80];
double priceML, weight, amount, cost;
cout << "Enter the name of the ingredient: "; cin.getline(name, 80); cout << endl;
cout << "Enter the amount of liquid purchased: "; cin >> amount; cout << endl;
cout << "Enter the cost of the liquid purchased: "; cin >> cost; cout << endl;
cout << "Enter the weight of the flavoring: "; cin >> weight; cout << endl;
priceML = (cost/amount);
Ingredient* newIngredient = new Ingredient(name, priceML, weight);
ingredient.push_back(*newIngredient);
}
int recipeSubMenu()
{
int thisChoice = 0;
system("clear");
cout << "Use the following menu to work with recipes: " << endl
<< "1. Display all Recipes" << endl
<< "2. Access Specific Recipe" << endl
<< "3. Create a New Recipe" << endl
<< "4. Return to Previous Menu" << endl;
cin >> thisChoice;
cin.ignore();
while (thisChoice > 4 || thisChoice < 1)
{
cout << "You have entered an invalid choice. Please try again: " << endl;
cin >> thisChoice;
}
return thisChoice;
}
int ingredientSubMenu()
{
int thisChoice = 0;
system("clear");
cout << "Use the following menu to work with ingredients: " << endl
<< "1. Display all Ingredients" << endl
<< "2. Access Specific Ingredient" << endl
<< "3. Add a New Ingredient" << endl
<< "4. Return to Previous Menu" << endl;
cin >> thisChoice;
cin.ignore();
while (thisChoice > 4 || thisChoice < 1)
{
cout << "You have entered an invalid choice. Please try again: " << endl;
cin >> thisChoice;
}
return thisChoice;
}