I am working on a card game. I have the program able to shuffle the deck 52 cards in an array, but the way that the random is making the cards is with the card number and not the card, I cannot think of a way to make the output the type of card it is instead.
what I have: 1, 2, 3, 4, 5, 6, 7, 8,etc...
what i want: a1, 21, 31, 41, etc...
where the first character is the card type and the second is the suit represented by a number. 10's will be three characters total 101, 102, 103, 104.
here is the code i am working on. Any help would be great :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int x;
int card[52];
int n;
srand(time(0));
for (int i=0; i<52; i++) {
card[i] = i;
}
while (cin >> n) {
for (int i=0; i<(52-1); i++) {
int r = i + (rand() % (52-i));
int temp = card[i]; card[i] = card[r]; card[r] = temp;
}
for (int c=0; c<n; c++) {
cout << card[c] << " ";
}
cout << endl;
}
cin >> x;
return 0;
}
|