Three Strikes and You Are Out Three Strikes is a popular game played for winning
ID: 3688349 • 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.
THIS CODE IS NOT WORKING FOR ME. IT GIVES ME AN ERROR THAT DEBUG ASSERTION FAILED! EXPRESSION: STRING SUBSCRIPT OUT OF RANGE. 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
I tried compiling it. It's working fine for me. Please do check once more nd met me know
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.