5
21/10/2024 6:47 pm
Topic starter
Write a program that generates and prints all possible cards from a standard deck of 52 cards: https://en.wikipedia.org/wiki/Standard_52-card_deck (without the jokers). The cards should be printed using the classical notation (like 5♠, A♥, 9♣ and K♦). The card faces should start from 2 to A. Print each card face in its four possible suits: clubs, diamonds, hearts and spades.
Use 2 nested for-loops and a switch-case statement.
2 Answers
4
21/10/2024 6:47 pm
Interesting task; Here is my solution and the output screenshot:
using System; class PrintADeckOf52Cards { static void Main() { for (int i = 2; i <= 14; i++) { for (int j = 5; j < 7; j--) { if (i < 11) { Console.Write("{0}{1} ", i, (char)j); } switch (i) { case 11: Console.Write("J{0} ", (char)j); break; case 12: Console.Write("Q{0} ", (char)j); break; case 13: Console.Write("K{0} ", (char)j); break; case 14: Console.Write("A{0} ", (char)j); break; } if (j == 3) { j = 7; } if (j == 6) { break; } } Console.WriteLine(); } } }
3
21/10/2024 6:49 pm
Here's a video with more complex solution (using methods):