Dynamic Rank
Lesson 5 of 6 in Coddy's Playing Cards Generator (Text Based) course.
Playing cards have 13 kinds of ranks:
- 1 - Ace (A)
- 2 - 10 Numbers
- 11 - Jack (J)
- 12 - Queen (Q)
- 13 - King (K)
Challenge
EasyMake your printCard function get as input also an integer (keep the suit input from before, make it the second input) that will represent the kind of the card.
The function will print totally dynamic card (from the input).
If the input integer (kind) is out of the range 1 to 13 (including), the kind symbol should be a space (" ").
The 10 Kind needs a special treatment
Try it yourself
#include <stdio.h>
#include <string.h>
void printCard(char* suit) {
char* suitSymbol = " ";
if (strcmp(suit, "club") == 0) suitSymbol = "♣";
else if (strcmp(suit, "diamond") == 0) suitSymbol = "♦";
else if (strcmp(suit, "heart") == 0) suitSymbol = "♥";
else if (strcmp(suit, "spade") == 0) suitSymbol = "♠";
printf("╔═════════╗\n");
printf("║ A ║\n");
printf("║ ║\n");
printf("║ ║\n");
printf("║ %s ║\n", suitSymbol);
printf("║ ║\n");
printf("║ ║\n");
printf("║ A ║\n");
printf("╚═════════╝\n");
}All lessons in Playing Cards Generator (Text Based)
1Introduction
Introduction