Question: Using the flowchart provided for the game of Mastermind, create a C program Start print: Welcome to the game of mastermind! Print: I will select
Using the flowchart provided for the game of Mastermind, create a C program







Start print: "Welcome to the game of mastermind!" Print: "I will select a random 4-digit number using digits 1 to 9 and you vill attempt to guess my number. InYou only have 10 rounds so use your choices wisely. To help you identify this number, I will tell you how many of your digits occur in exactly the same position as in my number, and how many digits occur in my number but in a different position Press l if you would like to play or press any number to exit "); loop Numbers= ["1", "2", "3", "4", "5", "6","7", "8", "9"} computerNumberl= picks random number from Numbers computerNumber2= picks random number from Numbers computerNumber 3= picks random number from Numbers computerNumber 4= picks random number from Numbers Loop (repeat 10 times) guess Numberl = INPUT ("Enter First Number") guess Number2 = INPUT ("Enter Second Number") guess Number3 = INPUT ("Enter Third Number") guess Number4 - INPUT ("Enter Fourth Number") Correct LocationAndNumber - 0 Correct NumberWrongNumber If False guessNumberla computer Number 1 True Balse Correct LocationAndNumber+=1 If Auess Numberl computer Number2 OR guessNumberl - computer Number3 OR GuessNumberly computerNumder True Correct NumberWrong Location=1 False guess Number2==> computerNumb72 True If AuessNumber2 computerNumberi OR False Correct LocationAndNumber+=1 guessNumber2 == computerNumber3 OR SuessNumber2=7 computerNumber4 True CorrectNumberWrongLocation+=1 If guess Number 3->> coxputerNumber3 True False Correct LocationAndNumber+=1 If Auess Number computerNumberi OR guessNumber3 == computer Number2 OR Suess Number 3-7 computerNumber 4 True Correct NumberWrong Location+=1 If False guess Number4-> coxputerNumber 4 If AuessNumber4 computerNumberl OR guessNumber4 == computerNumber2 False Correct LocationAndNumber+=1 OR SuessNumber4 computerNumber3 True CorrectNumberWrong Location+=1 OUTPUT Kou have" + Correct LocationAndNumber + "digits in the correct location and" + Correct NumberWrongLocation+ " digits in the wrong location if False Correct LocationAndNumber True EXIT LOOP False CorrectLocationAndNumber True OUTPUT "Congratulations, you win" OUTPUT "Sorry, you lost" YES Would you like to play again?" YES Would you like to play again?" No End
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
