CS 200 - Assignment 3

Due Thursday, Oct 11th by 11:59 PM

Bulls and Cows

Write a program that allows the user to play the game of Bulls and Cows against the computer.  Bulls and Cows is similar to the game Mastermind.

The computer picks a sequence of 3 random digits (0 through 9).  The user tries to guess the sequence picked by the computer by guessing each digit of the sequence.  The computer checks each digit entered by the user as follows:

The user wins when he/she gets 3 Bulls, guessing the correct digits in the correct order.

Example run (user input in bold red):

Your guess? 0 0 0
0 bulls, 0 cows
Your guess? 1 1 1
0 bulls, 0 cows
Your guess? 2 2 2
1 bulls, 2 cows
Your guess? 2 3 3
0 bulls, 1 cows
Your guess? 4 2 4
2 bulls, 1 cows
Your guess? 0 2 4
2 bulls, 0 cows
Your guess? 3 2 4
2 bulls, 0 cows
Your guess? 5 2 4
2 bulls, 0 cows
Your guess? 6 2 4
3 bulls, 0 cows
you win!

Getting started

Download CS200_Assign3.zip.

If you have the Marmoset Add-in installed, you can import the zip file using File->Import....

If you do not have the Marmoset Add-in installed, create a new folder, extract the contents of the zip file into the folder, navigate into the folder using a file browser, and then double-click the solution file (CS200_Assign3.sln).

If you are using Linux or Mac OS X, extract the zip file into a new folder.  In a terminal window, use the make command to compile the program and the ./BullsAndCows command to execute the program.

Hints

The following statement should occur near the beginning of your program (before you generate the random sequence of digits):

srand(time(NULL));

To generate a random int value in the range 0 through 9, use the following expression:

rand() % 10

You can use an array to store the sequence of random digits.

Submitting

If you have the Marmoset Add-in installed, you can submit online automatically by using the Tools->Submit... menu item.  Just type in your Marmoset username and password and click Submit.  After a few seconds, you should see a dialog box informing you whether or not the submission was uploaded successfully.  If successful, the dialog will look like this:


If you do not have the Marmoset Add-in installed, or if the automatic online submission does not work, create a zip file containing your entire project and manually upload it to the Marmoset server.  (See the submission instructions for details.)