Code:
#include <stdio.h>
#include <stdlib.h>
int getRandomNum(int nLow, int nHigh)
{
int nRandomValue;
nRandomValue = nLow + rand() % (nHigh - nLow + 1);
return nRandomValue;
}
void main()
{
char cont, yes, no, color1, color2, color3, color4, answerA, answerB, answerC, answerD, R, B, Y, G, Az, Bz, Cz, Dz;
int fixed1, fixed2, fixed3, fixed4, ctr;
int play = 1, correct = 0;
printf("*************************************************************************************************************************");
printf("\t\t\t\t\t\tI AM THE MASTER OF YOUR MIND");
printf("\t\t\t\t\t\t************************************************************************************************************************");
printf("*\t\t\t\t\t\t#\t#\t#\t#\t#\t\t\t\t\t *");
printf("\n************************************************************************************************************************");
while(play == 1)
{
do
{
fixed1 = getRandomNum(1,4);
fixed2 = getRandomNum(1,4);
fixed3 = getRandomNum(1,4);
fixed4 = getRandomNum(1,4);
}
//This will generate a random number that will be stored in fixed1,2,3,4
while(fixed1==fixed2||fixed1==fixed3||fixed1==fixed4||fixed2==fixed3||fixed3==fixed4||fixed2==fixed4);
printf("Select the colour you want to enter or 'Q' to Quit:\n'R' for RED, 'B' for BLUE, 'G' for GREEN, 'Y' for YELLOW\n");
getchar();
//This for loop is to limit the number of tries to max 10
for(ctr = 1; ctr <=10; ctr ++)
{
printf("Enter 4 colours\n");
scanf("%c,\t%c,\t%c,\t%c,",&color1, &color2, &color3, &color4);
getchar();
Az = 0, Bz = 0, Cz = 0, Dz = 0;
switch(color1)
{
case 'R' : Az = 1; break;
case 'B' : Az = 2; break;
case 'G' : Az = 3; break;
case 'Y' : Az = 4; break;
}
switch(color2)
{
case 'R' : Bz = 1; break;
case 'B' : Bz = 2; break;
case 'G' : Bz = 3; break;
case 'Y' : Bz = 4; break;
}
switch(color3)
{
case 'R' : Cz = 1; break;
case 'B' : Cz = 2; break;
case 'G' : Cz = 3; break;
case 'Y' : Cz = 4; break;
}
switch(color4)
{
case 'R' : Dz = 1; break;
case 'B' : Dz = 2; break;
case 'G' : Dz = 3; break;
case 'Y' : Dz = 4; break;
}
correct = 0;
if(Az == fixed1)
answerA = '@';
correct++;
if(Bz == fixed2)
answerB = '@';
correct++;
if(Cz == fixed3)
answerC = '@';
correct++;
if(Dz == fixed4)
answerD = '@';
correct++;
if(Az==fixed2||Az==fixed3||Az==fixed4)
answerA = 'O';
if(Bz==fixed1||Bz==fixed3||Bz==fixed4)
answerB = 'O';
if(Cz==fixed1||Cz==fixed2||Cz==fixed4)
answerC = 'O';
if(Dz==fixed1||Dz==fixed2||Dz==fixed3)
answerD = 'O';
if(Az!=fixed2&&Az!=fixed3&&Az!=fixed4)
answerA = 'X';
if(Bz!=fixed1&&Bz!=fixed3&&Bz!=fixed4)
answerB = 'X';
if(Cz!=fixed1&&Cz!=fixed2&&Cz!=fixed4)
answerC = 'X';
if(Dz!=fixed1&&Dz!=fixed2&&Dz!=fixed3)
answerD = 'X';
printf("%c %c %c %c", answerA, answerB, answerC, answerC);
if(correct == 4)
{
ctr = 10;
printf("Congratulation, you have won !\n");
printf("Do you want to play a new game? <Y/N>");
scanf("%c", &cont);
if(cont == 'Y')
play == 1;
if(cont == 'N')
printf("\nThank you for playing! hehexd");
}
if(correct < 4)
printf("\nYou Lose!\n");
printf("Do you want to play a new game? <Y/N>");
scanf("%c", &cont);
if(cont = 'Y')
play == 1;
if(cont = 'N')
printf("\nThank you for playing!");
}
getchar();
}
}