#include <iostream> #include<cmath> #include<ctime> #include<string> #include <iomanip> #include <fstream> using namespace std; int main() { const int NUMBER_OF_CARDS = 52; int deck[NUMBER_OF_CARDS]; string suits[] = { "Spades", "Hearts", "Diamonds","Clubs" }; string ranks[] = { "Ace","2","3","4","5","6","7","8","9","10""Jack","King","Queen" }; for (int i = 0; i < NUMBER_OF_CARDS; i++) deck[i] = i; srand(time(0)); for (size_t i = 0; i < NUMBER_OF_CARDS; i++) { int index = rand() % NUMBER_OF_CARDS; int temp = deck[i]; deck[i] = deck[index]; deck[index] = temp; } for (int i = 0; i < 4; i++) { string suit = suits[deck[i] / 13]; string rank = ranks[deck[i] % 13]; cout << "Card Number " << deck[i] << ": " << rank << " of " << suit << endl; } return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter