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:

• If a digit entered by the user occurs in the correct position, it counts as a "Bull"
• If a digit entered by the user occurs in the random sequence the computer chose, but is not in the correct position, it counts as a "Cow"

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 00 bulls, 0 cowsYour guess? 1 1 10 bulls, 0 cowsYour guess? 2 2 21 bulls, 2 cowsYour guess? 2 3 30 bulls, 1 cowsYour guess? 4 2 42 bulls, 1 cowsYour guess? 0 2 42 bulls, 0 cowsYour guess? 3 2 42 bulls, 0 cowsYour guess? 5 2 42 bulls, 0 cowsYour guess? 6 2 43 bulls, 0 cowsyou win!`

Getting started

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.)