Sorry for the spaghetti code, I don't have much experience with C++ (or coding in general for that matter) but here is my code... Also first time posting on stack overflow so apologies for improper formatting. I have been scouring the internet for the last 4 hours. Please tell me this is a simple fix. I have tried using std::vector ingredients.
//Program_2.h
#pragma once
#include <vector>
#include <string>
#include <iostream>
namespace sandwich
{
class SandwichMaker
{
public:
vector<string> ingredients;//<-- causing a few errors
int s = 0;
int Control();
void Menu(int &s, vector<string> &vec);
void PrintSandwich(vector<string> &vec);
private:
};
}
//Program_2.cpp
#include "Program_2.h"
using namespace std;
using namespace sandwich;
int SandwichMaker::Control()
{
SandwichMaker swm;
//vector<string> ingredients;
swm.Menu(swm.s, swm.ingredients);
while (swm.s > 0)
{
swm.Menu(swm.s, swm.ingredients);
}
system("PAUSE");
return 0;
}
void SandwichMaker::Menu(int &s, vector<string>& vec)
{
SandwichMaker swm;
cout << "Please choose what you would like to do and type the ingredient (1 and 2 only)\n (0 quit, 1 add ingredient, 2 remove ingredient, 3 make sandwich): ";
cin >> s;
string tempIngredient = "";
switch (s)
{
case 1://add
//cout << "Enter the ingredient you are going to add.\n";
cin.ignore();
getline(cin, tempIngredient);
vec.push_back(tempIngredient);
cout << " Ingredient has been added\n";
break;
case 2://remove
if (!vec.empty())
vec.pop_back();
else
cout << " Nothing has been added yet\n";
break;
case 3: //make the sandwich
swm.PrintSandwich(vec);
break;
default:
break;
}
}
void SandwichMaker::PrintSandwich(vector<string>& vec)
{
cout << "Your sandwich contains: ";
for (size_t i = 0; i < vec.size(); i++)
{
cout << i << ", " << vec[i] << endl;
}
}
cant post an images soo link? https://i.stack.imgur.com/yYvS0.jpg of all the errors that are getting spit out because of vector.