#include <stdio.h>#include<stdlib.h>#include<time.h>#include<string.h>#include<ctype.h>voidGenerateCharcomputer[]) { inti =0, J, T; Srand (Time (NULL)); while(I <4) {T= rand ()%Ten+'0'; for(j =0; J < I; ++j)if(T = =Computer[j]) Break; if(J = =i) {Computer[i]=T; ++i; } }}intIs_valid (Charman[]) { intI, J; if(! (IsDigit (man[0]) && IsDigit (man[1]) && IsDigit (man[2]) && IsDigit (man[3]) && man[4] ==' /')) return 0; for(i =0; I <3; ++i) for(j = i +1; J <4; ++j)if(Man[i] = =Man[j])return 0; return 1;}intCompareCharMan[],Charcomputer[]) { intI, j, a =0, B =0; for(i =0; I <4; ++i) for(j =0; J <4; ++j)if(Computer[i] = = Man[j] && i = =j)++A; Else if(Computer[i] = =Man[j])++b; if(A = =4) {printf ("You bet\n"); return 1; } if(A = =0&& b = =0) {printf ("0000\n"); return 0; } while(A >0) {Putchar ('A'); --A; } while(B >0) {Putchar ('B'); --b; } Putchar ('\ n'); return 0;}intUsr_input (Chararray[]) {printf ("Please input four different letters:\n"); if(SCANF ("%s", array)! =1) {printf ("unkown error!\n"); return 1; } return 0;}voidExit_output (Charcomputer[]) {printf ("The answer is:%c%c%c%c\n", computer[0], computer[1], computer[2], computer[3]);}voidErr_output (Charstr[]) {printf ("%s\n", str);}intMainvoid){ Charcomputer[ -]; Charman[ -]; Generate (computer); while(1) {usr_input (man); if(STRCMP (Man,"EXIT") ==0) || (STRCMP (Man,"Exit") ==0) {exit_output (computer); return 0; } if(!Is_valid (man)) {Err_output ("Invalid input!"); Continue; } if(Compare (man, computer))return 0; }}
C Basics-Guessing the number game (graphical interface done by MFC)