Thread: Bulls & Cows - C Program

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    108

    Bulls & Cows - C Program

    Hey everyone,

    I need help understanding the exercise I have and if possible to give me steps on how to figure it out.

    I need to build a Bulls & Cows program.

    Small Explanation of Bulls and Cows:
    The numerical version of the game is usually played with 4 digits, but can also be played with 3 or any other number of digits.
    On a sheet of paper, the players each write a 4-digit secret number. The digits must be all different. Then, in turn, the players try to guess their opponent's number who gives the number of matches. If the matching digits are on their right positions, they are "bulls", if on different positions, they are "cows". Example:

    • Secret number: 4271
    • Opponent's try: 1234
    • Answer: 1 bull and 2 cows. (The bull is "2", the cows are "4" and "1".)

    The first one to reveal the other's secret number wins the game. As the "first one to try" has a logical advantage, on every game the "first" player changes. In some places, the winner of the previous game will play "second". Sometimes, if the "first" player finds the number, the "second" has one more move to make and if he also succeeds, the result is even.
    The secret numbers for bulls and cows are usually 4-digit-numbers, but the game can be played with 3 to 6 digit numbers (in every case it is more difficult than with 4).

    Unfortunately i have different instructions that this one that i'll post after I understand the steps that I need to do and actually code the normal game.

    Can someone give me a step to step guide on what to start with?
    I'm in my first year program so i might not be very precise on what i'm asking.

    Please let me know if you need more information about what i'm asking.

    All help appreciated

    Last edited by YannB; 12-10-2013 at 05:31 PM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'd strongly suggest you develop the turn based code first, and get that working OK, before adding anything else.

    From main, call a menu function, and display the choices you need, such as play a game, or quit playing. From menu function, you call the gameOn function, and begin play, or quit and return to main (which might have just two lines of code in it).

    In gameOn, you'll play one game, calling other functions to make it manageable in size, and the errors, easy to catch. Some function should check if the game isWon() or not.

    Start with the basic flow of the game, and put off irrelevant details for now, to help keep the focus on the core logic needed for a two player game.

    Post back if you get stuck, but it is required that you post your program, and be rather specific with your questions. Things like "Help!", by itself, will tend to be ignored to save time for serious students with specific problems.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My first major program- Bulls and cows Game
    By Suhasa010 in forum C Programming
    Replies: 7
    Last Post: 09-06-2013, 04:34 AM
  2. Replies: 2
    Last Post: 12-11-2012, 12:25 AM
  3. Help needed in cows and bulls
    By Nikolas in forum C Programming
    Replies: 14
    Last Post: 01-13-2012, 07:06 PM
  4. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  5. Replies: 5
    Last Post: 08-16-2007, 11:43 PM