c++ program. We use studio visual 2015 All requirements must be met. please help
ID: 3680338 • Letter: C
Question
c++ program. We use studio visual 2015 All requirements must be met. please help!!!
Playing A Game For Relaxing 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
Explanation / Answer
// Three Strikes is a popular game played for 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 contestant wins if she / he fills out the price of the car
// before picking out all three strikes.
#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);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.