I have a vector of strings and it has three colors. My output only gives me one the first color 'red' where i want it to be random. vector<string> colors = {"red", "green", "yellow"};
there is something wrong with this code
Variety x= static_cast<Variety>(rand()%3);
fruit.insert(make_pair(x,colors[rand()%3]));
i tried doing +1 but that just makes it green.
enum class Variety {
orange,
pear,
apple
};
vector<string> colors = {"red", "green", "yellow"};
struct Fruit {
Variety v; string color; // red, green or orange
};
int main() {
multimap<Variety,string> fruit;
bool foundOrange;
for (auto j = 0; j < (rand() % 100 + 1); ++j) {
Variety x = static_cast<Variety>(rand() % 3);
fruit.insert(make_pair(x, colors[rand() % 3]));
}
return EXIT_SUCCESS;
}