Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,172 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,923 people online right now. Registration is fast and FREE... Join Now!




Mastermind C++ Game help

 
Reply to this topicStart new topic

Mastermind C++ Game help

Zedaine
5 Dec, 2007 - 11:06 AM
Post #1

New D.I.C Head
*

Joined: 14 Nov, 2007
Posts: 3


My Contributions
I need some help with my next lab. The purpose of this program is a game called Mastermind. It it supposed to randomly create 4 letters 'a' through 'f' and you have 8 tries to guess the 4 letters before it game overs on you. I seem to have everything working but I need to be able to the the user how many letters and positions he/she got right on each guess, and I can't seem to figure that out. Here is my code so far... (I have the answer displayed for testing purposes)

CODE

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>

using namespace std;

main()
{
    int size = 4;
    int range = 6;
    char lowest = 'a';
    string guess;
    int number;
    int correct;
      int position;

    srand(time(0));
        string answer = "";
        for (int i = 0; i < size; i++)
        {
            char ch = lowest + rand() % range;
            answer += ch;
        }
    
    
    number = 1;
    correct = 0;
    position = 0;
    
    while (number <= 8)
    {
        cout << "Guess #" << number << ": Enter 4 letters that are 'a' through 'f': ";
        cout << answer;
        cout << "\n";
        cin >> guess;
            
        if (guess == answer)
        {
            cout << "Right!  It took you " << number << " move";
            if (number != 1) cout << "s";
            cout << "." << endl;
        }
        
        while (position < size)
        {
            if (size == position) correct++;
            position++;
        }
        number++;
    

        cout << "Correct position: " << position << endl;
        cout << "Correct letter:   " << correct << endl;
    
    
    }
    
    cout << "You are all out of guesses.\n";
    cout << "GAME OVER\n\n";

    return 0;
}

User is offlineProfile CardPM
+Quote Post

dallas786
RE: Mastermind C++ Game Help
1 Apr, 2008 - 04:52 PM
Post #2

New D.I.C Head
*

Joined: 1 Apr, 2008
Posts: 2


Hi,
i just want it to know if you find the correct codes for mastermind becuase i have the same lab project & i don't have any clue where to go.
Please if you have the codes can you please email me at dallas_786@hotmail.com.

thanks in advance.........


QUOTE(Zedaine @ 5 Dec, 2007 - 12:06 PM) *

I need some help with my next lab. The purpose of this program is a game called Mastermind. It it supposed to randomly create 4 letters 'a' through 'f' and you have 8 tries to guess the 4 letters before it game overs on you. I seem to have everything working but I need to be able to the the user how many letters and positions he/she got right on each guess, and I can't seem to figure that out. Here is my code so far... (I have the answer displayed for testing purposes)

CODE

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>

using namespace std;

main()
{
    int size = 4;
    int range = 6;
    char lowest = 'a';
    string guess;
    int number;
    int correct;
      int position;

    srand(time(0));
        string answer = "";
        for (int i = 0; i < size; i++)
        {
            char ch = lowest + rand() % range;
            answer += ch;
        }
    
    
    number = 1;
    correct = 0;
    position = 0;
    
    while (number <= 8)
    {
        cout << "Guess #" << number << ": Enter 4 letters that are 'a' through 'f': ";
        cout << answer;
        cout << "\n";
        cin >> guess;
            
        if (guess == answer)
        {
            cout << "Right!  It took you " << number << " move";
            if (number != 1) cout << "s";
            cout << "." << endl;
        }
        
        while (position < size)
        {
            if (size == position) correct++;
            position++;
        }
        number++;
    

        cout << "Correct position: " << position << endl;
        cout << "Correct letter:   " << correct << endl;
    
    
    }
    
    cout << "You are all out of guesses.\n";
    cout << "GAME OVER\n\n";

    return 0;
}




Hi,
i just want it to know if you find the correct codes for mastermind becuase i have the same lab project & i don't have any clue where to go.
Please if you have the codes can you please email me at dallas_786@hotmail.com.

thanks in advance.........
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 12:36AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month