I am trying to make a blackjack game, and I am stuck trying to figure out how to convert the dealt card to a face card(if it is one).
So far I have the program randomly choose between 2-14. I then want to say:
1 2 3 4 5 6 7 8 9
|
char jack = 'j';
int card = 11;
if (card == 11)
{
card = jack;
}
cout << card;
|
I want it to display j, but instead it is displaying 106(the ascii number for j).
I saw online about itoa, but I am not understanding that, and I don't even know if that is what I am looking for here?
Also, would it be easier to use string instead of char?
Last edited on
You could write
cout << ( char )card;
or
cout << static_cast<char<( card );
But what if, like in my original program, it could be 2-10, and I still want it to display the integer?
(sorry I didn't write the original program in the original post. My program has card = to a random num between 2-14, so it won't always be 11)
Last edited on
1 2 3 4 5 6
|
if (card < 11)
cout << card;
else if (card == 11)
cout << 'j';
else if (card == 12)
//...
|
My favorite way to make a deck of cards:
1 2 3 4 5 6 7 8 9 10 11 12
|
string faces[] = {"diamonds", "clubs", "hearts", "spades"};
string values[] = {"ace", "two", "three", ... , "jack", "queen", "king"};
const int SIZE = 52;
int deck[SIZE];
for (int i = 0; i < SIZE; i++)
deck[i] = i;
// Use random values to shuffle the deck
for (int i = 0; i < SIZE; i++)
cout << value[deck[i] % 13] << " of " << face[deck[i] / 13] << endl;
|
Last edited on