I am trying to create an array of object type teaStep, aswell as attempting to reorder a list to a random list.
The function makeSteps
is meant to initiate the variables and store them in an array and output them.
The function randomizeSteps
is meant to make an array of ints and randomize their order, before outputting the new array.
Just wondering if this is the right way to do it.
[edited]
Using a vector, I now have this:
auto makeSteps()
{
auto all_steps = std::vector<teaStep>{};
all_steps.emplace_back("Pick your tea", 1);
all_steps.emplace_back("Boil water", 2);
all_steps.emplace_back("Get tea bag in mug or pot", 3);
all_steps.emplace_back("Pour boiled water over teabag", 4);
all_steps.emplace_back("Wait!", 5);
all_steps.emplace_back("Remove teabag", 6);
all_steps.emplace_back("Add milk and/ or sugar", 7);
all_steps.emplace_back("Mix, drink and enjoy", 8);
return all_steps;
}
auto randomizeSteps()
{
vector <int> ranstep;
for (int i = 1; i < 9; i++)
ranstep.push_back(i);
auto rng = std::default_random_engine{};
std::shuffle(std::begin(ranstep), std::end(ranstep), rng);
return ranstep;
}
To add to this, once this is complete, I must be able to utilise the objects in the vectors, however when I try this I get an error, example below:
//should go through the object in vectors, and compare the field Order, to int a.
teaStep findStep(int a, std::vector<teaStep> vectors)
{
for (int b = 0; b < 8; b++)
{
teaStep test = vectors[b];
if (test.getOrder == a)
return test;
}
}
The error I get is "no conversion from int to int(..."