I was trying to make an array picking random from another array, but it throws an exception, I wonder why, here is my code:
class mastermind {
private:
string color[9] = { "red", "orange", "yellow", "green", "cyan", "blue", "purple", "white", "black" };
string pick[4] = { " "," "," "," " };
public:
mastermind() {};
void setColor() {
for (int i = 0; i < sizeof(pick); i++) {
int random = rand() % 9;
string temp = color[random];
pick[i] = temp;
}
};
};
> for (int i = 0; i < sizeof(pick); i++)
This doesn't tell you how many elements an array has.
This does.
sizeof(pick) / sizeof(pick[0])