Code:#include<stdio.h> #include<math.h> #include<time.h> #include<stdlib.h> int fnCompare(int luckyNum,int inNum) { int i; if ((inNum <1) || (inNum > 100)) {i =1;} else if (luckyNum > inNum) {i =2;} else if (luckyNum < inNum) {i =3;} else {i =4;} return(i); } int fnLuckyNum() { int value; srand(time(NULL)); value= 1 + (int) rand()%100; return (value); } int main() { int luckyNum,input,temp,count,bestScore; int boolean; char choice,enterKey; bestScore=100; choice='y'; fflush(stdin); do { luckyNum=fnLuckyNum(); count=1; {input =1; while ((input>0)&&(input<=100)) { printf("\nGuess what is the lucky number< range 1 to 100>: "); scanf("%d",&input); printf("\n"); temp=fnCompare(luckyNum,input); switch (temp) { case 1: {printf("The program will be quit...");break;} case 2: {printf(" Too small! Guess again < or -ve number to quit>.\n\n");count++;break;} case 3: {printf(" Too large! Guess again < or -ve number to quit>.\n\n");count++;break;} case 4: {printf("---Lucky! Right. The lucky number is <%d>. \n",luckyNum); printf("---Number of attempts [%d]\n",count); input=-1; if (count<bestScore) bestScore=count; break;} } } } printf("\nBest Score so far <%d>.\n",bestScore); printf("\nPlay again? Type 'y' for YES [all other characters for No] : "); scanf("%c%c",&choice,&enterKey); printf("%c",choice); } while (choice != 'y'); getchar(); return 0; }