Solution: Lets Play Cards
The solution to the cards coding challenge is provided in this lesson.
Problem 1: Solution
Press + to interact
struct Card {dchar suit;dchar value;}void main () {}
Solution explanation
- Lines 2 and 3:
Since we have to store the value
and suit
of the card, one of the simplest designs is to use two dchar
members.
Problem 2: Solution
Press + to interact
import std.stdio;struct Card {dchar suit;dchar value;this(dchar s, dchar v) { // constructorsuit = s;value = v;}}void printCard(Card card) {write(card.suit, card.value);}void main() {auto card = Card('♠','4');printCard(card);}
Solution explanation
- Line 14:
Our goal is to print the suit shape and value together, ...