Code:
//Ant, Bear, Cat, Dog, Emu, Goat, Lizard, Monkey, Parrot, Rabbit, Snake, and Tiger//
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
char LetterSwap(char a)//swaps invalid randomed char to other valid which wasn't randomed out//
{ if (a=='F') a='M';
else if (a=='H') a='P';
else if (a=='I') a='R';
else if (a=='J') a='S';
else if (a=='K') a='T';
return a;
}
int main(){
char rand1='0',rand2='0',rand3='0',rand4='0';
char a,b,c,d;
char diff;
int times,guessnumber=1;
while (rand1==rand2 ||rand1==rand3 || rand1==rand4 ||rand2==rand3||rand2==rand4||rand3==rand4)//Equal randoms to be changed//
{
srand(time(NULL));
rand1=(rand()%12)+'A';
rand2=(rand()%12)+'A';
rand3=(rand()%12)+'A';
rand4=(rand()%12)+'A';
}
rand1=LetterSwap(rand1);//uses functions that swaps invalid to unrandomed characters//
rand2=LetterSwap(rand2);
rand3=LetterSwap(rand3);
rand4=LetterSwap(rand4);
printf("%c-%c-%c-%c\n",rand1,rand2,rand3,rand4);
printf("MASTERMIND GAME\n\nI got a secret code\n");
printf("Please select level of difficulty(L-low, H-high):");
scanf("%c",&diff);
if(diff=='L') printf("You want a low level of difficulty\n");
else if (diff=='H') printf("Excellent, you want a high level of difficulty\n");
else{
printf("INVALID!");
goto Done;}
for(times=0;times<=10;times++)
{
printf("Enter guess%d:",guessnumber);
scanf("%c %c %c %c",&a,&b,&c,&d);
if (a==b||a==c||a==d||b==c||b==d||c==d)
printf("Repeated");
}
Done: system("pause");
return 0;}
This is unfinished. I can't move on till i finish the looping part..It gives me a problem . When Testing it..Some outputs correct then suddenly it will not print "Repeated" even though there is a repeated letter. THANKS!