Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Arrays3.cpp /* Name: * Program: 2 * Description: This program demonstrates Arrays * Date: */ #include #include #include using namespace std; int main() { string

Arrays3.cpp

/* Name:

* Program: 2

* Description: This program demonstrates Arrays

* Date:

*/

#include

#include

#include

using namespace std;

int main()

{

string suit[4] = {"Hearts","Clubs","Spades","Diamonds"};

string value[13] = {"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"};

int Sval, Cval;

int dealtSuit[52];

int dealtValue[52];

int x, y;

bool valid;

char var;

srand((unsigned)time(0)); // "Seed" the random number generator

cout << "This program deals a deck of cards. ";

for (x = 0; x < 52; x++)

{

var = ' ';

while (var != 'y')

{

cout << "Enter 'y' to deal a card and 'q' to quit: ";

cin >> var;

if (var == 'q')

return 0;

}

valid = false;

while (!valid)

{

Sval = rand() % 4;

Cval = rand() % 13;

if (x > 0)

{

valid = true;

for (y = 0; y < x; y++)

{

if ((dealtSuit[y] == Sval)&&(dealtValue[y] == Cval))

valid = false;

}

}

else

valid = true;

}

dealtSuit[x] = Sval;

dealtValue[x] = Cval;

cout << "Your card is the " << value[Cval] << " of " << suit[Sval] << " ";

}

cout << "Out of cards! ";

return 0;

}

/* End of program evaluation:

* The code works as specified.

*/

Modify Arrays3.cpp so that the program plays Blackjack with a user. Make a basic menu system (review your 155 examples).

When run the program, you should see ONE card the computer has and one card that you have, and you should be able to HIT (get a new card) or STAY (keep your current cards and let the computer deal). If you do not BUST, after you stay the computer will try to beat your score. If either you or the computer get 21 total, that is an automatic win. If either busts, the other automatically wins. I recommend you move the main functionality of my code to a function called deal(), and then this makes the main a lot shorter and easier to follow. Note that only the value really matters with regard to the score the suit is just to ensure that each value only occurs four times per deck.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Multidimensional Array Data Management In Databases

Authors: Florin Rusu

1st Edition

1638281483, 978-1638281481

More Books

Students also viewed these Databases questions

Question

explain what is meant by redundancy

Answered: 1 week ago