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:
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!
I have these codes but doesnt work whitenite why?? I dont have too much time,, can you type where is wrong and how to fix it?? Did you remem ber you gave me opinions like;
#include <iostream>
usingnamespace std;
int main(int, char**){
int EXIT_VALUE = 0;
char strn[80];
char arr[80];
int len=strlen(strn);
do{
cout<<"Enter a positive integer ("<<EXIT_VALUE<<") to exit:";
cin>>strn;
if (cin.fail()) {
cout << "*** error: inputs must be an integer" << endl;
continue; }
elseif(strn<0){
cout<<"*** error: inputs must be greater than zero"<<endl;
continue;
}
bool flag=true;
for(int x=0;x<len;x++) {
arr[x]=(strn[x]);
if(arr[x] == strn[(len-1)-x]) {
flag = true;
}
else {
flag = false;
}
}
if(flag){
cout<<strn<<" is a Palindrome"<<endl;
}
else {
cout<<strn<<" is not a Palindrome"<<endl;
}
while(strn!=0);
system("pause");
return 0;
For future reference, you shouldn't hi-jack other people threads. You should have just added this to your original request, and it will show up as a 'new' item.
Thank you for your help, @whitenite1. However, we are not allowed to use any "shortcuts" that we haven't learned in the class already - lame I know - but I was able to write a code without using the erase function, although the erase thing would have been MUCH easier and faster. Will keep that in mind for future problems!
Okay. Good luck on your program. Looks a LOT more complicated than what I did. Not even sure how those functions work. Oh yeah, you shouldn't call srand() more than once. Call it at the start of your function, then just use the rand()%# afterward.
I'll be here if you need any further help..