如果总和要高于 21,我需要帮助更改 21 点中 ace 的整数值,C
I need help changing the integer value of ace in blackjack if the total sum is going to be higher then 21, C
在我的 21 点游戏中,ace 的整数值固定为 11,但在这种情况下,当一名玩家获得 ace 但她手中的牌的总价值将高于 21 我想要整数值王牌是 1.
void deal(const Card * const Deck, int value, int size, int size_1, int size_2){
int i, j, length;
char anotherCard[2];
char name1[30];
char name2[30];
int valueName1 = 0, valueName2 = 0, valueDealer = 0;
printf("Name player one > ");
scanf("%s", name1);
printf("Name player two > ");
scanf("%s", name2);
printf("\nWelcome %s and %s, lets begin!\n\n", name1, name2);
getchar();
while (valueName1 < 21 || valueName2 < 21 || valueDealer < 17){
printf("%s's card:\n", name1);
for (i = 0; i < size; i++){
printf("%5s of %-8s%c", Deck[i].decks, Deck[i].suits, (i + 1) % 2 ? '\t' : '\n');
if (valueName1 > 21 && Deck[i].value == 11){
Deck[i].value = 1; //error on this line
valueName1 += Deck[i].value;
printf("value > %d\n", valueName1);
}
else{
printf("value > %d\n", valueName1);
}
}
int main(void){
Card allCards[52];
Card cardValue[52];
char *suitname[] = { "spades", "hearts", "diamonds", "clubs" };
char *deckname[] = { "ace", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "jack", "queen", "king" };
int cardvalue[] = { 11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10 };
void fillDeck(Card * const Deck, const char *suit[], const char *deck[], const int value[]){
int s;
for (s = 0; s < 52; s++){
Deck[s].suits = deck[s % 13];
Deck[s].decks = suit[s / 13];
Deck[s].value = value[s % 13];
}
return;
}
我的结构:
typedef struct card{
const char *suits;
const char *decks;
int value;
};
错误信息:
错误 C2166:左值指定常量对象
您声明 Deck
为
const Card * const Deck
这意味着 Deck
是指向常量数据的常量指针,即您无法更改指针,并且(更重要的是)您无法更改它指向的数据。您需要删除第一个 const
才能使其正常工作
Card * const Deck
在我的 21 点游戏中,ace 的整数值固定为 11,但在这种情况下,当一名玩家获得 ace 但她手中的牌的总价值将高于 21 我想要整数值王牌是 1.
void deal(const Card * const Deck, int value, int size, int size_1, int size_2){
int i, j, length;
char anotherCard[2];
char name1[30];
char name2[30];
int valueName1 = 0, valueName2 = 0, valueDealer = 0;
printf("Name player one > ");
scanf("%s", name1);
printf("Name player two > ");
scanf("%s", name2);
printf("\nWelcome %s and %s, lets begin!\n\n", name1, name2);
getchar();
while (valueName1 < 21 || valueName2 < 21 || valueDealer < 17){
printf("%s's card:\n", name1);
for (i = 0; i < size; i++){
printf("%5s of %-8s%c", Deck[i].decks, Deck[i].suits, (i + 1) % 2 ? '\t' : '\n');
if (valueName1 > 21 && Deck[i].value == 11){
Deck[i].value = 1; //error on this line
valueName1 += Deck[i].value;
printf("value > %d\n", valueName1);
}
else{
printf("value > %d\n", valueName1);
}
}
int main(void){
Card allCards[52];
Card cardValue[52];
char *suitname[] = { "spades", "hearts", "diamonds", "clubs" };
char *deckname[] = { "ace", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "jack", "queen", "king" };
int cardvalue[] = { 11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10 };
void fillDeck(Card * const Deck, const char *suit[], const char *deck[], const int value[]){
int s;
for (s = 0; s < 52; s++){
Deck[s].suits = deck[s % 13];
Deck[s].decks = suit[s / 13];
Deck[s].value = value[s % 13];
}
return;
}
我的结构:
typedef struct card{
const char *suits;
const char *decks;
int value;
};
错误信息: 错误 C2166:左值指定常量对象
您声明 Deck
为
const Card * const Deck
这意味着 Deck
是指向常量数据的常量指针,即您无法更改指针,并且(更重要的是)您无法更改它指向的数据。您需要删除第一个 const
才能使其正常工作
Card * const Deck