Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ ONLY Write a program similar to Mastermind, except you will use 3 digits ins

ID: 3748264 • Letter: C

Question

C++ ONLY

Write a program similar to Mastermind, except you will use 3 digits instead of colors. Running the program should look like the following:

Alternatively if you are not able to find the answer within ten moves, a message and the answer is displayed, as follows:

Notes

I suggest you store the digits to be guessed as separate values, either as int or char values. When choosing 's' to set the digits to be guessed, note that input has all three digits entered next to each other, with no spaces between them.

As in the previous program, do not use srand(), as it will cause your program's output to not match the expected output.

When generating the three original values to be guessed, for the second and third values you should somehow use a loop to ensure that those values are distinct from the previous values already chosen. Using break and continue can help with this.

Stages

Write your program in stages as follows, where the number of points for each stage is shown:

(20 points) Display the instructions and find and display the three distinct characters in the range 0..9. Running your program should look like:

Program: 2 MasterMind The program selects 3 distinct random digits 0..9. On each turn you guess 3 digits. Program indicates how many are correct. You have 10 moves to guess the number. Good luck! Press 's' to set the three digits, or 'r' to randomize them: r Values to guess are: 367 Exiting...

NOTE; OUTPUT FOR "000" AND "999" SHOULD LOOK LIKE THIS

In place Out of place

-------- ------------

1. Your guess:

You entered: 123 0 1  

2.Your guess:

Hidden digits are: 367

2. Your guess:

You entered: 456 0 1

3. Your guess:

Exiting loop...

Better luck next time

. Exiting program...

Explanation / Answer

#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>

using namespace std;

int main()
{
int siz = 5;
int rangee = 9;
char low = '0';
string guesss;
int num;
int crct;
int pos;
bool game_Over = false;

srand(time(0));

string ans = "";
for (int i = 0; i < siz; i++)
{
  char ch = low + rand() % rangee;
  ans += ch;
}


num = 1;
crct = 0;
pos = 0;

while (!game_Over)
{
  cout << "Guess #" << num << ": Enter 5 numbers that are '0' through '9': ";
  cout << ans;
  cout << " ";
  cin >> guesss;

  if (guesss == ans)
  {
   cout << "Right! It took you " << num << " move";
   if (num != 1) cout << "s";
   cout << "." << endl;
   game_Over = true;
   
  }
  
  for (int i = 0; i < 5; i++){
   if (guesss[i] == ans[i]){
    crct = ;

   }
   
  }

  while (pos < siz)
  {
   if (siz == pos) crct++;
   pos++;
  }
  num++;


  cout << "Correct pos: " << pos << endl;
  cout << "Correct letter:   " << crct << endl;


}


cout << "GAME OVER ";

system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote