exercises/ex01/cards.c
int card_val(char card_name[2]) {
   int val = 0;
   switch (card_name[0]) {

      /* Queens, Kings, and Jacks are all worth ten points */
      case 'K':
      case 'Q':
      case 'J':
         return 10;

      /* Aces are worth eleven points */
      case 'A':
         return 11;

      /* Return 0 and exit loop if user tries to exit program */
      case 'X':
         return 0;

      /* Otherwise return numeric value of card, or 0 if invalid */
      default:
         val = atoi(card_name);
         if ((val < 1) || (val > 10)) {
            puts("I don't understand that value!");
            return 0;
         }
         return val;
   }
}
/* Returns the value of a card, based on a 2-character input. Valid card
   strings include 'K', 'Q', 'J', 'A', and numbers 2-10. Returns 0 if input
   is invalid.
*/
Returns the value of a card, based on a 2-character input.
Returns the value of a card based on a 2 - character input .
int card_val(char card_name[2]) {
   int val = 0;
   switch (card_name[0]) {
      case 'K':
      case 'Q':
      case 'J':
         return 10;
      case 'A':
         return 11;
      case 'X':
         return 0;
      default:
         val = atoi(card_name);
         if ((val < 1) || (val > 10)) {
            puts("I don't understand that value!");
            return 0;
         }
         return val;
   }
}
int card_val ( char card_name [ 2 ] ) { int val = 0 ; switch ( card_name [ 0 ] ) { case ' ' : case ' ' : case ' ' : return 10 ; case ' ' : return 11 ; case ' ' : return 0 ; default : val = atoi ( card_name ) ; if ( ( val < 1 ) || ( val > 10 ) ) { puts ( " " ) ; return 0 ; } return val ; } }
Returns the value of a card, based on a 2-character input.
Returns the value of a card based on a 2 - character input .
/* Queens, Kings, and Jacks are all worth ten points */ /* Aces are worth eleven points */ /* Return 0 and exit loop if user tries to exit program */ /* Otherwise return numeric value of card, or 0 if invalid */