Im making a blackjack game, there is an array cards:
Code:int cards[] = {1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,\ 8,8,9,9,9,9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13};Code:void dealplayer1 (){ double R = (double)rand()/(double)RAND_MAX; double P; player1.card1 = cards[rand() % 52]; while (isalpha(player1.card1)) player1.card1 = cards[rand() % 52]; cards[player1.card1] = 'X'; if (player1.card1 == 11 || player1.card1 == 12 || player1.card1 == 13 ) player1.card1new = 10; else player1.card1new = player1.card1; player1.card2 = cards[rand() % 52]; while (isalpha(player1.card2)) player1.card2 = cards[rand() % 52]; cards[player1.card2] = 'X'; if (player1.card2 == 11 || player1.card2 == 12 || player1.card2 == 13 ) player1.card2new = 10; else player1.card2new = player1.card2; player1.total = player1.card1new + player1.card2new; P = (double)1 - (((double)21 - (double)player1.total)/(double)21); while (R <= P) player1.extra = cards[rand() % 52]; while (isalpha(player1.extra)) player1.extra = cards[rand() % 52]; cards[player1.extra] = 'X'; if (player1.extra == 11 || player1.extra == 12 || player1.extra == 13 ) player1.extranew = 10; player1.total += player1.extranew; }
This is the code for player1 of the game the problem im having is increase how many cards he can get Is there a better way to do this? looks a bit messy