Question
Colors : Y Yellow O Orange R Red B Blue G Green P - Purple Colors Y Yellow O
Colors :
Y – Yellow
O – Orange
R – Red
B – Blue
G – Green
P - Purple
Colors
Y – Yellow
O – Orange
R – Red
B – Blue
G – Green
P - Purple
You are to write a program to allow the user to play Mastermind.Mastermind is a game where the user tries to guess the color andorder of pegs that the computer has chosen. The peg colors areshown to the right. The computer will randomly choose the solutionpegs and store them in a string representing the colors (Forexample: YPBRP). The user will then try to guess the pegs. Aftereach guess the computer will tell the user how many colors theyguess correctly AND how many pegs were in the correct position.Using that information, the user would then make another guess.This continues until the user guesses all of the colors in thecorrect order.
There should be a constant NUM_OF_PEGS, this should be declaredabove main. Start the NUM_OF_PEGS at 3 when testing your program,but should be 5 when turned in.
The following functions should be written
makeSolution
Creates the solution string and returns it. The solution stringis made up of randomly chosen colors. The constant (NUM_OF_PEGS)will determine how many colors (pegs) are in the solution.
allowUserToGuess
Asks the user to type in their guess. It checks to make surethat the string they enter is the correct length. If it is not thecorrect length, asks the user to enter another guess. (You do NOThave to make sure that the colors are correct)
numberCorrectColorAndPosition
Determines how many pegs are in the correct position, meaninghow many colors are in the correct spot.
numberCorrectColor
Determines how many peg colors were guessed correctly. (This isprobably the most challenging function due to that fact that therecan be multiples of the same color)
directions
This function prints the directions. The statements are givenbelow, so you can copy them.
cout << "Master Mind" << endl;
cout << "The object of this game is to guessthe colored pegs that the " << endl;
cout << "computer has randomly chosen. Youwill guess the sequence by " << endl;
cout << "typing in the first letter of thecolor that you choose." << endl;
cout << "The color choices are:" < cout <<"tY-YellowtO-OrangetR-RedtB-BluetG-GreentP-Purple"; cout << "If the computer had a solution ofBYRBP, and the user entered OBGRP"; cout << "The computer would tell the userthat they have 3 colors correct and"; cout << "1 color in the correct position.Using this information, the user"; cout << "would then guess again until theyget all of the colors correct and"; cout << "in the correct order."; The main function should Sample output is given below Hints Sample Output Programmed By Lori Tetzner Master Mind The object of this game is to guess the colored pegs thatthe computer has randomly chosen. You will guess the sequence by typing in the first letter of the color that you choose. The color choices are: Y-Yellow O-Orange R-Red B-Blue G-Green P-Purple If the computer had a solution of BYRBP, and the user enteredOBGRP The computer would tell the user that they have 3 colors correctand 1 color in the correct position. Using this information, theuser would then guess again until they get all of the colors correctand in the correct order. Do you want to play Master Mind: y I have chosen my color pegs Solution is: YBYPO //only printed for you to see how gameworks The solution has 5 pegs Enter your guess: RBYGP Your guess is: RBYGP There are 3 peg colors correct and 2 pegs in the correctposition Enter your guess: RBYOR Your guess is: RBYOR There are 3 peg colors correct and 2 pegs in the correctposition Enter your guess: RBY There are 5 pegs in the solution, your guess does not have the correct number of pegs. Tryagain!!! Enter your guess: RRRRR Your guess is: RRRRR There are 0 peg colors correct and 0 pegs in the correctposition Enter your guess: BYOGR Your guess is: BYOGR There are 3 peg colors correct and 0 pegs in the correctposition Enter your guess: BYOPY Your guess is: BYOPY There are 5 peg colors correct and 1 pegs in the correctposition Enter your guess: OBYPY Your guess is: OBYPY There are 5 peg colors correct and 3 pegs in the correctposition Enter your guess: PBYOY There are 5 pegs in the solution, your guess does not have the correct number of pegs. Tryagain!!! Enter your guess: PBYOY Your guess is: PBYOY There are 5 peg colors correct and 2 pegs in the correctposition Enter your guess: YBYPO Your guess is: YBYPO You Won!!!!! The pegs that were chosen were YBYPO Do you want to play another game of Master Mind? (Y/N): n
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started