int choicesFlags[12];
int difficultyFlag = 0;
int gameFlag = 0;
int correctInPlace = 0;
int correctLetter = 0;
int trs = 0;
int checkFlag = 0;
int i, j, x, y, length, position, num;
main(){
system("cls");
cout<<"Welcome to the Mastermind Game!\n";
puts("");
cout<<"I got a secret code.\n";
cout<<"\nCHOICE: 'A', 'B', 'C', 'D', 'E', 'G', 'L', 'M', 'P', 'R', 'S', 'T' \n";
}
}
randomGenerated[i] = 0;
cout<<"the secret code is "<<randomGenerated<<"\n";
cout<<"Sorry! You have exceeded the maximum number of tries\n";
cout<<"Thank you for playing!";
askToPlay();
}
}
int checkNum(){
length = strlen(userInput); // strlen - counts the num of char on a string
if(length != 4) {
cout<<"Input is not 4 characters\n";
cout<<"\n";
checkFlag = 2;
trs--;
return checkFlag;
}
else checkAnswer();
}
void checkAnswer(){
for(i = 0; i < 4; i++)
switch(toupper(userInput[i])) {
case 'A': choicesFlags[0]++; break;
case 'B': choicesFlags[1]++; break;
case 'C': choicesFlags[2]++; break;
case 'D': choicesFlags[3]++; break;
case 'E': choicesFlags[4]++; break;
case 'G': choicesFlags[5]++; break;
case 'L': choicesFlags[6]++; break;
case 'M': choicesFlags[7]++; break;
case 'P': choicesFlags[8]++; break;
case 'R': choicesFlags[9]++; break;
case 'S': choicesFlags[10]++; break;
case 'T': choicesFlags[11]++; break;
default: cout<<"Invalid Animal!\n\n"; trs--; askGuess(); break;
}
for(i = 0; i < 12; i++) {
if(choicesFlags[i] > 1) {
checkFlag = 0;
}
choicesFlags[i] = 0;
}
if(checkFlag == 0) {
cout<<"Invalid input: Repeated Animal\n\n";
trs--;
askGuess();
//trs--;
}
}
char lowDiff(){
char code[24]=" ";
for(i=0;i<4;i++){
for(j=0;j<4;j++){
if(randomGenerated[i] == toupper(userInput[j]))
correctLetter++;
}
switch(toupper(userInput[i])) { //strcat - inserts a copy of the source string to the destination string
case 'A': strcat(code, "Ant"); break;
case 'B': strcat(code, "Bear"); break;
case 'C': strcat(code, "Cat"); break;
case 'D': strcat(code, "Dog"); break;
case 'E': strcat(code, "Emu"); break;
case 'G': strcat(code, "Goat"); break;
case 'L': strcat(code, "Lizard"); break;
case 'M': strcat(code, "Monkey"); break;
case 'P': strcat(code, "Parrot"); break;
case 'R': strcat(code, "Rat"); break;
case 'S': strcat(code, "Snake"); break;
case 'T': strcat(code, "Tiger"); break;
}
if (i>=0 && i<=2)
strcat(code, ", ");
else strcat(code, "; ");
}
printf("Your guess is%s", code);
if (correctLetter == 4){
cout<<"\nCongratulations, you win! You got the code in "<<trs<<"guess(es)\n";
askToPlay();
}
else {
cout<<"Your score is "<<correctLetter<<"\n\n";
correctLetter = 0;
}
}
void askToPlay(){
do {
cout<<"\nDo you want to play again? [Y]/[N]"<<endl;
cin>>answ;
if ((answ=='y')||(answ=='Y'))
{
cout<<"\t\t\tWelcome back!"<<endl;
}
else if ((answ=='n')||(answ=='N'))
{
cout<<"\nThank You for Playing!!!"<<endl; exit(EXIT_FAILURE);
}
else
{
cout<<"Invalid Input!!!"; askToPlay();
}
}while((answ !='Y')&&(answ !='N')&&(answ !='y')&&(answ !='n')&&(answ !='b')&&(answ!='B'));
}
can anyone tell how to fix this program. my problem is when i click y in you want to play again the question/word repeat and when it reach the max of 10 you can not play anymore..