#include <iostream>
#include <cstdlib>
#include <time.h>
usingnamespace std;
int main(){
int guess;
srand( time(NULL) );
int number = rand() % 10000;
cout<< "Welcome to the game of Mastermind. ";
cout<< "You have 12 chances to guess a combination of ";
cout<< "4 non-repeating digits from 1 to 8."<<endl;
cout<< "Enter your digits as xxxx. " <<endl;
cout<< "The computer chose: "<< number <<endl;
if(guess != number)
do{
cout<< "Enter your guess: ";
cin>> guess;
cout<<"Correct Digits: ";
cout<<"Correct Spots: ";
cout<<"Guesses left: ";
}while(guess != number);
if(number == guess){
cout<<"you win";
cout<<"you got it in "<< tries<< "moves";
}
else
cout<<"you lost, the answer was"<<number;
}
int correctdigits(int a[],int g[], int size[]){
int count = 0;
for (int i = 0; i < 4; i++){
for (int j = 0; j < 4; j++){
if(a[i] == g[i])
count++;
}
}
}
int correctspots(int a[], int g[], int size){
int count = 0;
for(int i = 0; i < size; i++){
if(a[i] == g[i])
count++;
}
return count;
}
In the classic game of Mastermind, a random set of 4 digits (from 1-6) are selected by the computer. A player will have 12 attempts to guess the pattern of digits. The computer will respond after every guess the user makes--with a number of correct digits that was made, and the number of spots the digits are in.
The player will have 12 attempts to guess the pattern of digits.
I am supposed to record the array of moves the user made. And there is more.
What I did so far is provide a simple structure of a welcome screen, and functions for correct digits and spots but I need help into turning it into a full working code.