Multiple Cards
Lesson 6 of 6 in Coddy's Playing Cards Generator (Text Based) course.
Let's show multiple cards!
Challenge
MediumNow, we want to add support for multiple cards, change the input of printCard from integer (kind) and string (suit) to integer array (kinds) and string array (suits), for example:
The input - [1, 2, 3], ["heart", "club", "spade"] will result in 3 cards, Ace of Hearts, Two of Clubs and Three of Spades.
You can assume the length of the arrays are the same
Check the test cases for the right formats, you should add a single space between the cards.
Try it yourself
#include <stdio.h>
#include <string.h>
void printCard(int kind, 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 = "♠";
char kindBuf[4] = " ";
if (kind == 1) strcpy(kindBuf, "A");
else if (kind >= 2 && kind <= 10) sprintf(kindBuf, "%d", kind);
else if (kind == 11) strcpy(kindBuf, "J");
else if (kind == 12) strcpy(kindBuf, "Q");
else if (kind == 13) strcpy(kindBuf, "K");
printf("╔═════════╗\n");
if (kind == 10) printf("║ 10 ║\n");
else printf("║ %s ║\n", kindBuf);
printf("║ ║\n");
printf("║ ║\n");
printf("║ %s ║\n", suitSymbol);
printf("║ ║\n");
printf("║ ║\n");
if (kind == 10) printf("║ 10 ║\n");
else printf("║ %s ║\n", kindBuf);
printf("╚═════════╝\n");
}All lessons in Playing Cards Generator (Text Based)
1Introduction
Introduction