Mastermind

This is a discussion on Mastermind within the C++ Programming forums, part of the General Programming Boards category; i am having a spot of trouble making this program, and i would like as much as possible, i have ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    8

    Mastermind

    i am having a spot of trouble making this program, and i would like as much as possible, i have consulted many, including my teacher and all of my fellow students. THe job is to make a program to have the computer play a game of Mastermind against a human opponent. The
    computer will select 4 coloured pegs at random from 6 possible choices (red, green, yellow, blue,
    orange, purple). A colour may be chosen more than once. You will then try and guess what pegs the
    computer has chosen by selecting a guess of 4 pegs. Each time you make a guess the computer will
    score the guess by showing white and black pegs. A white peg means you have the right colour in the
    right position. A black peg means you have the right colour at the wrong position. You have 10
    chances to guess the pegs the computer has chosen.
    i ahev already done this much:






    // game1.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include <iostream.h>
    #include <iomanip.h>
    #include <string.h>
    void main()
    {
    char lmargin[5]=" ";
    char guess[10] [5];
    char score[10] [5];
    int j,k;

    // initialize guess and score arrays with some values
    // values should be blank spaces in actual game

    void getGuess(char g[5])
    {
    char x;
    int n,count=0;
    cin.get(g,5);
    cin.ignore(80,'\n');
    cout << '/'<<g<<'/'<<endl;
    x=g[count];
    do
    {
    switch (x)
    {
    case 'r':
    case 'y':
    case 'b':
    case 'o':
    case 'g':
    case 'p': count=count+1;
    break;
    default:count=8;
    break;
    }
    x=g[count];
    }
    while (count < 4);
    if (count==8)
    {
    cout <<"\nInvalid characters were entered."<<endl;
    cout << "Press any key to continue"<<endl;
    n=getch();
    strcpy(g," ");
    }
    }

    for (j=0; j<=9; j++)
    {
    strcpy(guess[j],"4243");
    strcpy(score[j],"5678");
    }

    // top line
    cout <<lmargin<<char(-38);
    for (j=1; j<7; j++) cout <<char(-60);
    cout <<char(-62);
    for (j=1; j<7; j++) cout <<char(-60);
    cout <<char(-65)<<endl;

    // title
    cout <<lmargin<<char(-77)<<" Guess"<<char(-77)<<" Score"<<char(-77)<<endl;

    // line under title
    cout <<lmargin<<char(-61);
    for (j=1; j<7; j++) cout <<char(-60);
    cout <<char(-59);
    for (j=1; j<7; j++) cout <<char(-60);
    cout<<char(-76)<<endl;

    // body
    for (k=0;k<=9;k++)
    {
    cout <<setw(4)<<k+1<<char(-77)<<' '<<guess[k]<<' '<<char(-77)<<' '<<score[k]<<' '
    <<char(-77)<<endl;
    }

    // bottom line

    cout<<lmargin<<char(-64);
    for(j=1;j<14;j++) cout<<char(-60);
    cout<<char(-39)<<endl;


    }

    i have no idea how to make the get guess function work nevermind the rest of the program. I would appreciate all help possible.
    Thank you.

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    367
    I looked through the code briefly. My guess is that you should try not to use so much void, make that get_guess function return the guessed value or something.

  3. #3
    Unregistered
    Guest
    are you using lawrenceville press by chance?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mastermind program problem with iterator
    By Truckomobil in forum C++ Programming
    Replies: 3
    Last Post: 06-08-2009, 01:16 PM
  2. Can anyone teach me how to write mastermind in GUI??
    By prefectticky in forum C++ Programming
    Replies: 18
    Last Post: 04-17-2009, 08:57 AM
  3. mastermind
    By roeyman in forum C Programming
    Replies: 11
    Last Post: 01-01-2009, 07:21 AM
  4. Algorithmic Mastermind Program
    By pr0n in forum C Programming
    Replies: 1
    Last Post: 05-12-2008, 11:02 PM
  5. coding mastermind in C, only got 2 probs..
    By lepricaun in forum C Programming
    Replies: 17
    Last Post: 07-24-2004, 09:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21