Lab18A

1. Write a program named Lab18A that will play Blackjack.
a. Define an enumerated type, cards, that has the values ACE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING. (Do this just above the function prototypes, before all the functions.)
b. Create an integer function called housePlay that will return a random integer between 2 and 21. (No parameters) (Note: put your srand(time(0)) statement at the beginning of the main function, and only do it once.)
c. Create an integer function named randomPick that will return a random number between 1 & 13. (No parameters)
d. Create a void function named drawTheCard that will accept a cards parameter and will draw the card for that value. (Sample cards shown below.)
e. Create an integer function named getPoints that will accept a cards value as a parameter and return the number of points for that card. (ACE = 1, JACK/QUEEN/KING = 10, all other cards = their face value)
f. Create a void function named PlayerPickCard (with one integer reference parameter named totalScore.) It will
i. call randomPick
ii. using the number from randomPick, determine the cards value based one the following table. Use a switch structure to determine the cards value.
1 – ACE 2 – TWO 3 – THREE 4 – FOUR 5 – FIVE
6 – SIX 7 – SEVEN 8 – EIGHT 9 – NINE 10 – TEN
11 – JACK 12 – QUEEN 13 – KINGiii. call drawTheCard sending the cards value as a parameter
iv. call getPoints sending the cards value as a parameter and add the returned value to totalScoreg. In your main function:
i. Call housePlay to determine the house’s total score. Print the house score with a label.
ii. Call PlayerPickCard twice sending a player score variable as a parameter.
iii. Ask the user if they want to pick another card. (They only get one more.) If they say yes, call PlayerPickCard again sending the player score variable as a parameter. (Do #’s iv & v, whether they picked again or not.)
iv. If the player score is over 21 print the score and a message saying they busted
v. Otherwise compare the player score to the house score. The one with the highest score wins. Print the player score along with a message saying who won.***** ***** *****
* A * * 2 * * J *
***** ***** *****

×
New Download