When it is the computer's turn to make a Mastermind guess, it should choose a random guess--that it has not already chosen. What you could do is put the numbers from 0000 to 9999 in an array, shuffle the array, and just move your way down the array whenever you want to pick a new random number. Another way is to initialize the array from 0000 to 9999. And whenever you need a random guess, grab a random one from the array, say from position r, move the last element in the array (which would be at position len-1) into position r, and then shrink the len. Keep a record of all previous guesses and their grades. If your random guess grades all previous guesses correctly, hurray, that's your next guess. Otherwise, choose another random guess. Reading input in old C: scanf ("%d",&i) reads an int into int variable i. scanf ("%s",s) reads a white-space terminated string into char *s. If s wasn't allocated large enough, you will do bad things. s should be allocated to 5 bytes, a byte for each digit of the guess, and the null terminator (which will be appended automatically). Correct: 1234 Computer guess: 5926 You give it a grade of (0,1). The computer remembers 5926 AND the computer remembers (0,1). The computer chooses a random guess. 8903. So, the computer grades 8903 against 5926. The grade is (1,0) which does not match (0,1), so the computer does not use the guess 8903, and chooses another one. Computer eventually chooses: 7208 which is graded (0,1) against 5926, so that's its second guess and is graded (1,0). So now, computer chooses a random guess: 9090 9090 is graded against 5926 and hopes for (0,1). 9090 is graded against 8903 and hopes for (1,0).