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

Three Strikes and You Are Out Three Strikes is a popular game played for winning

ID: 3689232 • Letter: T

Question

Three Strikes and You Are Out Three Strikes is a popular game played for winning a car. There are five chips, each with one of the digits of the price of the car, and three chips with X’s (strikes). All the digits of the price are different and unique (only one of its kind). The eight chips are placed in a bag. The contestant picks chips from the bag one by one. If the contestant picks a digit, she/he must guess which position in the price of the car the digit belongs. If she/he is right, the digit lights up on the board, and the digit is discarded from the bag. If not, the digit is placed back in the bag. If the contestant should pick a strike, the strike is removed from the bag. The contestant wins if she/he fills out the price of the car before picking out all three strikes. Requirements: You cannot pick a digit that was not in the price of the car. It's impossible to do that. After each pick, the number of strikes hit and the number of digits correctly placed must be shown on screen. And there must be a panel displayed to show the process of the game, locating the digits that were answered correct. At the end, regardless of losing or winning the game, the price of the car must be displayed on screen.the guessed digitd have to be shown in the gaps after each guess

My code is not working correctly and it does not meet all the requirements. any help would be appreciated. thank you

#include <algorithm>

#include <cstdlib>

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

/* function declarations */

void mycenter(string);

void mymenu();

void mypanel(string);

int myguess(string);

void myhidden();

string myfounddigits = " ";

/* main method */

int main()

{

/* function call to menu */

mymenu();

/*needed variables */

string select;

string myX;

srand((unsigned)time(0));

int mydigits[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};

random_shuffle(mydigits, mydigits + 9);

const int numberDigits = 5;

int randomint = mydigits[0];

for (int inc = 1; inc < numberDigits; ++inc)

{

randomint *= 10;

randomint += mydigits[inc];

}

myX = to_string(static_cast <long long> (randomint));

cout << randomint << " " << myX << endl;

do

{

mypanel(myX);

cout <<endl<<endl<<"Enter 'p' 2 pick a chip, or other keys 2 end the game: ";

cin >> select;

}

while (select[0] == 'p' || select[0] == 'P');

return 0;

}

/* menu module */

void mymenu()

{

cout <<"Welcome to 3 Strikes Game"<<endl<<endl;

}

/* center module */

void mycenter(string center)

{

int mynumber = ((80 - center.length())) / 2;

for (int inc = 1; inc <= mynumber; inc++)

cout << " ";

cout << center;

}

/* panel module */

void mypanel(string a)

{

static int strike;

static int placedDigits;

static int gates = 0;

++gates;

string myrestart;

cout << " -";

for (int inc = 0; inc < 8; inc++)

{

cout << "~-^-";

}

cout << "|";

cout << endl <<" |";

cout << " Strikes hit: ";

cout << strike;

cout << " |" << endl;

cout << " |";

cout << " Digits Placed: ";

cout << placedDigits << " |" << endl;

cout << " | |"<<endl<<" ";

cout << "| ";

cout << "Panel: $ ";

string location;

string partI, partII, partIII, partIV, partV;

partI = " _";

partII = " _";

partIII = " _";

partIV = " _";

partV = " _ ";

location = partI + partII + partIII + partIV + partV;

cout << location;

cout << " |" << endl;

cout << " | ";

cout << " 0 1 2 3 4 ";

cout << "|" << endl;

cout << " -";

for (int inc = 0; inc < 8; inc++)

{

cout << "~-^-";

}

cout << "|";

int wrong = 0;

if (gates > 1)

{

int myX = myguess(a);

if (myX == 0)

++placedDigits;

else if (myX == 1)

++strike;

}

if (strike == 3)

{

cout <<endl<<endl<< "you lost!";

cout <<endl<<endl<< "car price was: $"<< a;

cout <<endl<<endl<<"want 2 play again [y for yes or n for no]?: ";

cin >> myrestart;

while (myrestart[0] != 'y' && myrestart[0] != 'Y'&& myrestart[0] != 'n' && myrestart[0] != 'N')

{

cout <<endl<<"'y' for Yes, or 'n' for No: ";

cin >> myrestart;

}

if (myrestart[0] == 'y' || myrestart[0] == 'Y')

{

system("cls");

strike = 0;

placedDigits = 0;

mymenu();

myhidden();

return;

}

else if (myrestart[0] == 'n' || myrestart[0] == 'N')

{

cout << "Thanks for Playing! ";

cin.get();

exit(0);

}

}

}

/* guess module */

int myguess(string randomNumber)

{

int q;

int myX = (rand() % 7);

if (myX > 4)

{

cout <<endl<<endl<<"U picked a strike!";

return 1;

}

if (myX < 5)

{

cout <<endl<< "U picked the digit: ";

cout << randomNumber[myX];

cout <<endl<<endl<< "Enter the position of digit you think? ";

cin >> q;

while (q < 0 || cin.fail())

{

cout <<endl<< "Position Invalid!, Input again: ";

cin.ignore();

cin >> q;

}

if (q != myX)

{

cout <<endl<<endl<<"Sorry! U guessed wrongly!";

return 2;

}

if (q = myX)

{

cout <<endl<<endl<<"Correct, U picked correct position!";

myfounddigits[q] = randomNumber[q];

return 0;

}

}

return 2;

}

/* module hidden */

void myhidden()

{

int strike = 0;

int placedDigits = 0;

cout << " -";

for (int inc = 0; inc < 8; inc++)

{

cout << "~-^-";

}

cout << "|";

cout <<endl<< " |";

cout << " Strikes hit: ";

cout << strike;

cout << " |" << endl;

cout << " |";

cout << " Digits Placed: ";

cout << placedDigits << " |" << endl;

cout << " | | ";

cout << "| ";

cout << "Panel: $ ";

cout << " _ _ _ _ _ ";

cout << " |" << endl;

cout << " | ";

cout << " 0 1 2 3 4 ";

cout << "|" << endl;

cout << " -";

for (int inc = 0; inc < 8; inc++)

{

cout << "~-^-";

}

cout << "|";

}

Explanation / Answer

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <Windows.h>
using namespace std;

#undef max

void center(string);
void menu();
void panel(string);
int guessPosition(string);
void hiddenPanel();

string foundDigits = " ";

HANDLE hColors = GetStdHandle(STD_OUTPUT_HANDLE);

int main() {

       menu();
       string choice;
       string exit;
       string x;

       srand((unsigned)time(0));

       int digits[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
       random_shuffle(digits, digits + 9);
       const int numDigits = 5;
       int random_int = digits[0];

       for (int i = 1; i < numDigits; ++i)
       {
           random_int *= 10;
           random_int += digits[i];
       }

       x = to_string(random_int);
       cout << random_int << " " << x << endl;

       do {
           panel(x);
           cout << " Enter 'p' to pick a chip, or any other key to quit the game: ";
           cin >> choice;

       }
       while (choice[0] == 'p' || choice[0] == 'P');

       /*SetConsoleTextAttribute(hColors, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
       cout << " Don't feel good? So sorry as you didn't want to play the game. ";
       SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
       cout << " Do you want to play again (y/n)? ";
       getline(cin, exit);

       while (exit[0] != 'y' && exit[0] != 'Y' && exit[0] != 'n' && exit[0] != 'N') {
           SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_INTENSITY);
           cout << " Please enter 'y' for Yes, or 'n' for No: ";
           SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
           getline(cin, exit);
       }

       if (exit[0] == 'n' || exit[0] == 'N') {
           SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
           cout << " Programmer: Ishak R. Mahamoud - written for CISC 192/ C++ Programming. ";
           cout << "Thanks for using the game. So Long, Farewell! ";
           SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
           cin.get();
           cin.clear();
       }
       else if (exit[0] == 'y' || exit[0] == 'Y') {
           returns = 1;
       } */

       return 0;
}

void menu() {

   for (int i = 0; i < 20; i++) {
       SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
       cout << "~-^-";
   }

   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN| FOREGROUND_INTENSITY);
   cout << " *********** Welcome to Three Strikes Game *********** ";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " Pick a chip from a bag, the chip will contain ";
   cout << " a digit or strike, if it's a digit then guess ";
   cout << " which positon it belongs to the car's price ";
   SetConsoleTextAttribute(hColors, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " PANEL : _ _ _ _ _ <- this is the 0th position ";
   cout << " POSITION: 0 1 2 3 4 ";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " Accumulating three strikes will result in losing the game. ";

   for (int i = 0; i < 20; i++) {
       SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
       cout << "~-^-";
   }
}

void center(string centered)
{
   int number = ((80 - centered.length())) / 2;
   for (int i = 1; i <= number; i++)
       cout << " ";
   cout << centered;
}

void panel(string a) {
   static int strikes;
   static int digitsPlaced;
   static int gate = 0;
   ++gate;
   string restart;

   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " -";
   for (int i = 0; i < 8; i++) {
       SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
       cout << "~-^-";
   }
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << "|";
   cout << " |";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " Strikes hit: ";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_INTENSITY);
   cout << strikes;
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " |" << endl;
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " |";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " Digits Placed: ";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << digitsPlaced << " |" << endl;
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " | | ";
   cout << "| ";
   SetConsoleTextAttribute(hColors, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << "Panel: $ ";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);

   string placement;
   string part1, part2, part3, part4, part5;
   part1 = " _";
   part2 = " _";
   part3 = " _";
   part4 = " _";
   part5 = " _ ";

   placement = part1 + part2 + part3 + part4 + part5;
   cout << placement;

   //cout << foundDigits[0] << " " << a[0] << endl;

   //replace(part1.begin(), part1.end(), '_', a[0]);
   //replace(part2.begin(), part2.end(), '_', a[1]);
   //replace(part3.begin(), part3.end(), '_', a[2]);
   //replace(part4.begin(), part4.end(), '_', a[3]);
   //replace(part5.begin(), part5.end(), '_', a[4]);

   //cout << part1 << part2 << part3 << part4 << part5;



   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " |" << endl;
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " | ";
   SetConsoleTextAttribute(hColors, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
   cout << " 0 1 2 3 4 ";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << "|" << endl;
   cout << " -";

   for (int i = 0; i < 8; i++) {
       SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
       cout << "~-^-";
   }
   cout << "|";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);

   int wrong = 0;

   if (gate > 1) {
       int x = guessPosition(a);

       if (x == 0)
           ++digitsPlaced;
       else if (x == 1)
           ++strikes;
   }

   if (strikes == 3) {
       SetConsoleTextAttribute(hColors, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
       cout << " Sorry, you lost the game!";
       SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
       cout << " The price of the car was: $" << a;
       SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
       cout << " Do you want to play again (y/n)? ";
       cin >> restart;


       while (restart[0] != 'y' && restart[0] != 'Y' && restart[0] != 'n' && restart[0] != 'N') {
           SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_INTENSITY);
           cout << " Please enter 'y' for Yes, or 'n' for No: ";
           SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
           cin >> restart;
       }

       if (restart[0] == 'y' || restart[0] == 'Y') {
           system("cls");
           strikes = 0;
           digitsPlaced = 0;
           menu();
           hiddenPanel();
           return;
       }

       else if (restart[0] == 'n' || restart[0] == 'N') {
           SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
           cout << " Programmer: Ishak R. Mahamoud - written for CISC 192/ C++ Programming. ";
           cout << "Thanks for using the game. So Long, Farewell! ";
           SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
           cin.get();
           exit(0);
       }
   }

}

int guessPosition(string randomNumber) {

   int q;
   int x = (rand() % 7);


   if (x > 4) {
       SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_INTENSITY);
       cout << " You picked a strike!!!";
       SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
       return 1;
   }

   if (x < 5) {
       cout << " You picked the digit: ";
       cout << randomNumber[x];
       cout << " Which position do you think it is? ";
       cin >> q;

       while (q < 0 || cin.fail()) {
           SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_INTENSITY);
           cout << " Invalid position, input the position again: ";
           SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
           cin.ignore();
           cin >> q;
       }
       if (q != x) {
           SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_INTENSITY);
           cout << " Sorry! You guessed the wrong position";
           SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
           return 2;
       }

       if (q = x) {
           SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
           cout << " Correct, you picked the correct position!!!";
           SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
           foundDigits[q] = randomNumber[q];
           return 0;
       }
   }

   return 2;
}

void hiddenPanel() {
   int strikes = 0;
   int digitsPlaced = 0;

   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " -";
   for (int i = 0; i < 8; i++) {
       SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
       cout << "~-^-";
   }
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << "|";
   cout << " |";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " Strikes hit: ";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_INTENSITY);
   cout << strikes;
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " |" << endl;
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " |";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " Digits Placed: ";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << digitsPlaced << " |" << endl;
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " | | ";
   cout << "| ";
   SetConsoleTextAttribute(hColors, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << "Panel: $ ";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
   cout << " _ _ _ _ _ ";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " |" << endl;
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << " | ";
   SetConsoleTextAttribute(hColors, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
   cout << " 0 1 2 3 4 ";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
   cout << "|" << endl;
   cout << " -";

   for (int i = 0; i < 8; i++) {
       SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
       cout << "~-^-";
   }
   cout << "|";
   SetConsoleTextAttribute(hColors, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
}

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