fork download
  1. #include <stdio.h>
  2. //**************************************************************
  3. // Function: blackJackValue
  4. //
  5. // Purpose: Calculates the total value of a number of euro coins of different values.
  6. //
  7. // Parameters: card1 - char: the first card in your hand
  8. // card2 - char: the second card in your hand.
  9. //
  10. // Returns: result - an integer representing hand value.
  11. // will return 0 if the hand is invalid.
  12. //
  13. //**************************************************************
  14.  
  15. int blackJackValue (char card1, char card2){
  16. int value = 0;
  17. int i;
  18. //make a short array and iterate over it so I can re-use the switch block
  19. char cards[2] = {card1, card2};
  20. for (i=0; i<2; i++) {
  21. //Determine value of card and add it to the running total
  22. switch (cards[i]) {
  23. case 'A':
  24. value+=11;
  25. break;
  26. case '2':
  27. value+=2;
  28. break;
  29. case '3':
  30. value+=3;
  31. break;
  32. case '4':
  33. value+=4;
  34. break;
  35. case '5':
  36. value+=5;
  37. break;
  38. case '6':
  39. value+=6;
  40. break;
  41. case '7':
  42. value+=7;
  43. break;
  44. case '8':
  45. value+=8;
  46. break;
  47. case '9':
  48. value+=9;
  49. break;
  50. case 'T':
  51. case 'J':
  52. case 'Q':
  53. case 'K':
  54. value+=10;
  55. break;
  56. default: //If it's an invalid card, return 0
  57. return 0;
  58. }
  59. }
  60. return value;
  61. }
  62. int main(void) {
  63. // your code goes here
  64. printf("%d",blackJackValue('A', '#'));
  65. return 0;
  66. }
  67.  
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty