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