coverting an integer to a sinlge char

This is a discussion on coverting an integer to a sinlge char within the C++ Programming forums, part of the General Programming Boards category; im doing a blackjack program where if the random number is equal to 10 then it must convert it to ...

  1. #1
    Unregistered
    Guest

    Smile 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. #2
    junior member mix0matt's Avatar
    Join Date
    Aug 2001
    Posts
    144
    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);
    THIS IS NOT JUST A CHRONICLING OF THINGS WE HAVE DONE IN THE PAST BUT OUR RISE TO POWER.

  3. #3
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    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...
    Blue

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  2. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  3. Replies: 7
    Last Post: 06-16-2006, 09:23 PM
  4. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  5. checking if a char * is an integer
    By gregulator in forum C Programming
    Replies: 5
    Last Post: 04-16-2004, 09:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21