#include <stdio.h>
//**************************************************************
// Function: blackJackValue
//
// Purpose: Calculate the total points associated with the black jack hand
//
// Parameters:
//
// card1 - the first card in the hand
// card2 - the second card in the hand
//
// Returns: value of the hand (in points)
//
//**************************************************************
int blackJackValue (char card1, char card2){
char handArray[2][1] = {card1, card2}; //creating an array which holds the two cards associated with a specific hand. Each card is represented by a single character
int cardValues[2]= {0,0}; //initializing an array that will hold the values of the two cards in the hand
for (int i = 0; i < 2; i++) {
switch (handArray[i][0]) {
case 'T':
case 'K':
case 'Q':
case 'J':
cardValues[i]=10;
break;
case 'A':
if (i==1 && cardValues[0]==11){
cardValues[1]=1;
}
else{
cardValues[i]=11;
}
break;
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (i==0){
int cardValue1=card1-'0'; //converting the card value from a character digit to an integer. To do this subtracting the ASCII value for '0' from the ASCII value from the character digit (e.g., '3') to return the ASCII value for the numeric digit (e.g. 3)
cardValues[i]=cardValue1;
}
else if (i==1){
int cardValue2=card2-'0';
cardValues[i]=cardValue2;
}
break;
// default:
// printf("Not a valid card");
// break;
};
};
int totalPoints=cardValues[0]+cardValues[1]; //calculating total points
if (cardValues[0]==0 | cardValues[1]==0){
printf("There was an invalid card in the hand. Caution should be applied when interpreting the total points calculation.");
};
return totalPoints;
};
int main() {
int totalPoints= blackJackValue('A','#');
printf("Total Points Associated with Hand: %i\n", totalPoints);
return 0;
};