Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include<stdlib.h> # define N_DIGITS 4 # define MAX_QUERIES 12 void generate_ans

ID: 3529474 • Letter: #

Question



#include<stdlib.h>

# define N_DIGITS 4

# define MAX_QUERIES 12

void generate_answer(int[]);

void compare(int[],int[],int *,int *);

int main()

{int guess[ N_DIGITS],answer[ N_DIGITS];

int i,n,m,guesses;

int number,exact,inexact;


double average;

srand(0);

guesses=0;


printf("*** Welcome to the MATCH and HIT game*** ");

printf("The computer has selected a 4-digitnumber. ");

printf("Try to deduce it in 12 rounds of queries. ");

generate_answer(answer);

for(i=0;i< N_DIGITS;i++)

printf("%d",answer[i]);

printf(" ");


do

{guesses++;

printf("Round# %d Please enter your query (4digits):",guesses);

while(scanf("%d",&n)!=1||n>9999)

{while(getchar() != ' ' );

printf("invalid input ");

printf("Round# %d Please enter your query (4digits):",guesses);

}

m=1000;

for(i=0;i< N_DIGITS;i++)

{guess[i]=n/m;

n%=m;

m/=10;

}

compare(guess,answer,&exact,&inexact);

printf("%d hit and %dmatches ",exact,inexact);

}while(exact!= N_DIGITS&&guesses<12);

if(exact== N_DIGITS)

{printf("*****************************

Explanation / Answer

it is the nature of the rand to produce the same 'random' series everytime you use the same seed. try seeding with time instead.