The name of your C program file must be called mastermind.c, files with any other name will not be marked.
Your objective is to guess the number and the computer will respond by giving you one black for each digit that is guessed correctly and is in the correct place, and one white for each digit that is guessed correct but is in the wrong place. You will not be informed about which digits are correct. That part you will have to figure out for yourself.
You are to code this game in C, and perform the task of both the Player as well as the Programmer. You can assume that the user's guess will always be a valid four-digit number.
Suppose the answer is 3835. Then, the following guesses will yield the results as shown:
Two sample runs are given below (user's input is in bold):
Enter guess: 1234 Blacks: 1, whites: 0 Enter guess: 5678 Blacks: 1, whites: 1 Enter guess: 1655 Blacks: 1, whites: 0 Enter guess: 1788 Blacks: 0, whites: 1 Enter guess: 2275 Blacks: 3, whites: 0 Enter guess: 7275 Blacks: 4, whites: 0 Congratulations, you win!
Enter guess: 1234 Blacks: 0, whites: 2 Enter guess: 5678 Blacks: 0, whites: 2 Enter guess: 2121 Blacks: 2, whites: 0 Enter guess: 6565 Blacks: 0, whites: 0 Enter guess: 8787 Blacks: 2, whites: 0 Enter guess: 0 The answer is: 8721
/**********************************************************************/
/* Matric Number: U051234A */
/* Userid: u0501234 */
/* Lab: 4 */
/* Lab Group Number: 99 */
/* Lab TA's Name: Who needs a lab TA when you're Bill Gates? */
/* Lab Session Date: 05 April 2006 */
/* Lab Session Time: 0800 - 0945 */
/* Title: I'm a moron if I forget to change this. */
/* Purpose: I'm a moron if I forget to change this. */
/**********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* Declare function prototypes. */
/* ... */
int main(void)
{
/* Declare and initialize variables. */
/* ... */
/* Sets the seed to a random value based on the system time. */
/* This is done only once, at the beginning of the program. */
srand((unsigned int)time(NULL));
/* Your code goes here... */
return 0;
}
A total of 12 different hosts have accessed this document in the last 556 days; your host, 216.73.216.129, has accessed it 1 times.
If you're interested, complete statistics for this document are also available, including breakdowns by top-level domain, host name, and date.