Skip to content

Instantly share code, notes, and snippets.

@pbondoer
Created June 10, 2016 13:43
Show Gist options
  • Save pbondoer/0e8b7ea12af5d13c3eafdaab0feb5e5c to your computer and use it in GitHub Desktop.
Save pbondoer/0e8b7ea12af5d13c3eafdaab0feb5e5c to your computer and use it in GitHub Desktop.
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* black_jack_hand.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbondoer <pbondoer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/06/10 15:02:42 by pbondoer #+# #+# */
/* Updated: 2016/06/10 15:42:56 by pbondoer ### ########.fr */
/* */
/* ************************************************************************** */
int black_jack_hand(char *hand)
{
char card;
int score;
int as;
score = 0;
as = 0;
while (*hand)
{
card = *(hand++);
if (card >= '2' && card <= '9')
score += (card - '0');
if (card == 'T' || card == 'J' || card == 'D' || card == 'K')
score += 10;
if (card == 'A')
{
as++;
score += 11;
}
}
while (as > 0)
{
if (score > 21)
score -= 10;
as--;
}
return (score);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment