fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. static const size_t NumCardsInDeck = 24;
  5. static const size_t NumCardsPerHand = 5;
  6. static const size_t NumPlayers = 4;
  7.  
  8. const char* DECK[NumCardsInDeck] =
  9. {
  10. "Ace of Spades", "Nine of Spades", "Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades",
  11. "Ace of Hearts", "Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts",
  12. "Ace of Clubs", "Nine of Clubs", "Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs",
  13. "Ace of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds"
  14. };
  15.  
  16. int main()
  17. {
  18. const char* hands[NumPlayers][NumCardsPerHand];
  19. enum { Player1, Player2, Player3, Player4 }; // For indexing the hands.
  20.  
  21. std::cout << "We have " << NumPlayers << " hands of " << NumCardsPerHand << " cards." << std::endl;
  22. std::cout << "Total cards that will be dealt: " << NumPlayers * NumCardsPerHand << std::endl;
  23.  
  24. for(size_t i = 0 ; i < NumCardsInDeck; ++i) // for the total amount of cards
  25. {
  26. if(i < 3)
  27. {
  28. hands[Player1][0] = DECK[i];
  29. }
  30. else if(i < 6) // it's an else, so i > 2 is already implied.
  31. {
  32. hands[Player2][0] = DECK[i];
  33. }
  34. else
  35. {
  36. break;
  37. }
  38. }
  39.  
  40. std::cout << "hands[0][0] = " << hands[0][0] << std::endl;
  41. std::cout << "hands[1][0] = " << hands[1][0] << std::endl;
  42.  
  43. return 0;
  44. }
  45.  
  46.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
We have 4 hands of 5 cards.
Total cards that will be dealt: 20
hands[0][0] = Ten of Spades
hands[1][0] = King of Spades