0
我需要編寫一個函數,將雙張牌二十一點手牌的值作爲輸入,並打印出手的總點數。這是我迄今爲止,但總回報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;
}
任何幫助,將不勝感激。謝謝。
確定我沒有加入硬編碼輸入INT card_score(INT num_of_cards) { 炭card_value [SIZE]; int ace_seen = 0,total = 0; printf(「\ n \ n輸入卡號:」); scanf(「%i」,&num_of_cards); 對(INT I = 0; I
user2876750
打印num_of_cards輸入所需的值。查看它是否實際存儲在num_of_cards中。 –
是它打印出我輸入的num_of_cards作爲輸入 – user2876750