# Thread: coverting an integer to a sinlge char

1. ## coverting an integer to a sinlge char

im doing a blackjack program where if the random number is equal to 10 then it must convert it to a J,Q,K, doesnt matter any of those characters would be fine i just cant figure out how to do it any help would be greatly appreciated.

so when it says
you got a 3 10

it would say
you got a 3 K or J or Q

2. i you're not keeping track of cards, you could create an array of strings containing:

char* faceCards[] = { "10", "Jack", "Queen", "King" };

then randomize the index of the array (between zero and three);

3. Well I imagine you mean 11 is a jack and 12 is a queen and 13 is a king.

You could use 1 for an Ace.

You would do a rand() up to 13 for each card and in the "case" of a 1, 11, 12, 13... you would display the appropriate character.

Many ways to do this....

switch (My_Integer)
{
case 1:
cout << " A ";
break;
case 2: // you will have to include up through 10
cout << My_Integer;
break;
case 11:
cout << " J ";
break;
case 12:
cout << "Q";
break;
case 13:
cout << "K";
break;
}

Now you probably would have problems with addition since those last three equal 10 mathematically.... so consider stripping off the excess for your addition purposes.

if ((My_Integer == 11)||(My_Integer == 12)||(My_Integer == 11))
My_Integer = 10;

Now consider an Ace which can be an eleven or a one. You displayed it as a one and got it as an integer one, but need to start off using it as an eleven for mathmatics until the total is over 21 which will immediately subtract 10 from the final total, but it will do that only once.

Just some thoughts...