Hello!
I am writing a program that mimics the game Mastermind. However, I am having trouble getting past the first step. We are using letters as the "colors", a string containing "RGBYO". Each time it goes through trying to get the initial "secret code", it needs to get rid of whatever color it randomly picked so that it can not be used again. In other words, each "color" can only be used once. So if the program is generating a secret code to be guessed for this game, it can only come out with RGBY or GYBO, not something like GGYO or RGBB. I can not figure out how to remove the used color from the string. Below is my code:
#include <iostream>
#include <string>
#include <ctime>
void setSecretCode(char[]);
using namespace std;
int main()
{
char code[4]= {0};
setSecretCode(code);
cout << code[0] << code[1] << code[2] << code[3];
cout << endl;
system ("pause");
return 0;
}
void setSecretCode (char code[4])
{
string colors = "RGBYO";
int pos;
srand(time(NULL));
pos = rand() % 5;
code[0] = colors[pos];
srand(time(NULL));
pos = rand() % 4;
code[1] = colors[pos];
srand(time(NULL));
pos = rand() % 3;
code[2] = colors[pos];
srand(time(NULL));
pos = rand() % 2;
code[3] = colors[pos];
}
I tried colors = colors - colors[pos] as well as colors = colors - code[whateveritis], but the "code" is char and the "pos" is int, so it's telling me I can't convert within it (obviously). Any help would really be appreciated. Thank you!