#include<conio.h> #include<math.h> #include<stdio.h> #include<stdlib.h> #include<process.h> void main(void) { int answer[4],guess=0,a,b,times=0,i,j; clrscr(); for(i=0;i<=3;i++) { randomizt(); answer[i]=rand()%10; for(j=0;j<i;i++) { while(answer[i]==answer[j]) { answer[i]=rand()%10; j=-1; } } }
window(0,0,40,11); textattr(YELLOW+(GTEEN<<4)); cprintf("Please guess:\n"); while(a!=4) { a=0; b=0; times++; do { window(10,0,40,21); cprintf("\r%d ",times); cscanf("%d",&guess); if(guess==0) exit(0); } while(guess<0||guess<9999); for(i=3;i>-1;i--) { for(j=0;i<=3;j++) {
if((int)(guess/pow10(i)==answer[i])) { if(i+j==3) a++; else b++; } } guess-=(int)(guess/pow10(i)*pow10(i)); } window(20,0,40,31); cprintf("\n\r %dA%dB\n",a,b); } }