// Assignment Final Question 3
//
// Name: <Maribel Fuentes>
//
// Class: C Programming, <Fall 2024>
//
// Date: <December 2, 2024>
#include <stdio.h>
#include <ctype.h>
int cardValue(char card) {
if (card >= '2' && card <= '9') {
return card - '0';
} else if (card == 'T' || card == 'K' || card == 'Q' || card == 'J') {
return 10;
} else if (card == 'A') {
return 11;
} else {
return -1; // Invalid card
}
}
int blackjackHandValue(char card1, char card2) {
int value1 = cardValue(card1);
int value2 = cardValue(card2);
if (value1 == -1 || value2 == -1) {
printf("*** Invalid card input\n"); return -1;
}
int total = value1 + value2;
// Adjust for the case of two aces
if (card1 == 'A' && card2 == 'A') {
total = 12;
}
return total;
}
int main() {
char card1, card2;
scanf(" %c %c", &card1
, &card2
);
// Convert to uppercase to handle lowercase input
int score = blackjackHandValue(card1, card2);
if (score != -1) {
printf("The score is %d\n", score
); }
return 0;
}
Ly8gQXNzaWdubWVudCBGaW5hbCBRdWVzdGlvbiAzCi8vCi8vIE5hbWU6IDxNYXJpYmVsIEZ1ZW50ZXM+Ci8vCi8vIENsYXNzOiBDIFByb2dyYW1taW5nLCA8RmFsbCAyMDI0PgovLwovLyBEYXRlOiA8RGVjZW1iZXIgMiwgMjAyND4KCiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8Y3R5cGUuaD4KCmludCBjYXJkVmFsdWUoY2hhciBjYXJkKSB7CiAgICBpZiAoY2FyZCA+PSAnMicgJiYgY2FyZCA8PSAnOScpIHsKICAgICAgICByZXR1cm4gY2FyZCAtICcwJzsKICAgIH0gZWxzZSBpZiAoY2FyZCA9PSAnVCcgfHwgY2FyZCA9PSAnSycgfHwgY2FyZCA9PSAnUScgfHwgY2FyZCA9PSAnSicpIHsKICAgICAgICByZXR1cm4gMTA7CiAgICB9IGVsc2UgaWYgKGNhcmQgPT0gJ0EnKSB7CiAgICAgICAgcmV0dXJuIDExOwogICAgfSBlbHNlIHsKICAgICAgICByZXR1cm4gLTE7IC8vIEludmFsaWQgY2FyZAogICAgfQ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