我需要编写一个函数,将两张牌二十一点手的值作为输入,并打印出手的总点数。这是我到目前为止所拥有的,但总回报为 0。
int card_score(int num_of_cards)
{
char card_value[SIZE];
int ace_seen=0, total=0;
for (int i=0; i<num_of_cards;i++)
{
switch (card_value[i])
{
case 'a': case 'A':
total +=11;
ace_seen++;
break;
case 'k': case 'K':
case 'q': case 'Q':
case 'j': case 'J':
case 't': case 'T':
total +=10;
break;
case '9':
total +=9;
break;
case '8':
total +=8;
break;
case '7':
total +=7;
break;
case '6':
total +=6;
break;
case '5':
total +=5;
break;
case '4':
total +=4;
break;
case '3':
total +=3;
break;
case '2':
total +=2;
break;
default:
printf("Invalid cards. Please try again.");
break;
}
}
return total;
}
int main()
{
char card_value[SIZE];
int num_of_cards = 0;
int total;
int i = 0;
printf("\n\nEnter cards: ");
scanf("%c", &card_value[i]);
total = card_score(num_of_cards);
printf("\n\nYour score is %d: \n",total);
return 0;
}
任何帮助,将不胜感激。谢谢。