#include #include // for rand(), srand() #include // for time() using namespace std; int main() { char response; int seed = (int) time(NULL); cout << "seed is: " << seed << endl; srand(seed); do { // Prompt if user wants to play a game of blackjack cout << "Would you like to play a(nother) game of Black Jack?" << endl << "[y/n] "; cin >> response; // If they said yes, play it... if (reponse == 'y' || repsonse == 'Y') playBlackJack(); } while (repsonse == 'y' || reponse == 'Y'); return 0; } void playBlackJack(void) { // boolean flags to see if user/dealer wants to stay or continue bool userStays = false; bool dealerStays = false; // intialize scores for both players to 0 int userScore = 0; int dealerScore = 0; // deal first two cards to each user userScore += dealRandomCard("USER"); dealerScore += dealRandomCard("DEALER"); // this one should be hidden! userScore += dealRandomCard("USER"); dealerScore += dealRandomCard("DEALER"); do { // does the user want another card? if (userWantsAnotherCard()) userScore += dealRandomCard("USER"); else userStays = true; // does the dealer want another card? if (dealerWantsAnotherCard(dealerScore)) dealerScore += dealRandomCard("DEALER"); else dealerStays = true; // keep going until both user's stay } while (!userStays && !dealerStays); // compute the scores if (userScore > 21 && dealerScore > 21) cout << "We both bust! No Winner!" << endl; else if (userScore > 21) cout << "User busts! Dealer Wins!" << endl; else if (dealerScore > 21) cout << "Dealer busts! You win!" << endl; else if (userScore > dealerScore) cout << "You win!" << endl; else cout << "The dealer wins!" << endl; } int dealRandomCard(string player) { // get a random card int card = SomeKindOfFunctionToGetARandomCard(); // report what card was dealt. use the string parameter in the display cout << "Player " << player << " draws a "; SomeKindOfFunctionToDisplayACard(card); cout << endl; // NOTE: you have to remember to "hide" the first card dealt to the dealer // (computer) from the user -- i.e. don't output it. // How could you do that? // return the score of the card in blackjack return SomeKindOfFunctionToGetTheScoreOfTheCard(card); }