Thread: How to assign a character to an integer and print it?

  1. #1
    Registered User
    Join Date
    Mar 2012

    How to assign a character to an integer and print it?

    I have a very simple Blackjack program that I've coded for an assignment - It takes two random cards from a deck (2 #s from a 13-number array), prints them, and if their sum is 21, it prints "Blackjack!" next to them. When the number selected from the array is 1, the Ace, I reassign it a value of 11. When the number selected from the array is either 11, 12, or 13, I reassign it a value of 10. This all appears to work fine, and the program runs successfully.

    However, what I need to happen is for the program to print the high card character (J,Q,K,A) instead of its value. How can I do this?

    --As a side question, when I first run the program, it gives me all random numbers and works fine, but each subsequent run results in the same, now not-so-random numbers. Is there some way to fix this?

  2. #2
    Registered User
    Join Date
    Dec 2011
    Why don't you use switch case for that, you can create a seperate function with switch case which checks for those cards and prints equivalent characters....

  3. #3
    Registered User
    Join Date
    Sep 2006
    The random number functions are made to return the SAME numbers, when they are not seeded. (That is for testing purposes on hardware and software both).

    So seed the random number function first - and just seed it ONE time, before you use it. After that, it will run through random numbers. You should know that "random" is not really decently random, unless great care is taken with the program. As a beginner, not aware of the problem, just know that "random" may or may not be decently random, depending on other factors in your program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-21-2008, 01:12 PM
  2. Assign null to a character array.
    By mahedee in forum C Programming
    Replies: 1
    Last Post: 08-06-2008, 07:16 AM
  3. Howto assign an address to an integer variable
    By daYz in forum C Programming
    Replies: 18
    Last Post: 02-24-2008, 10:19 AM
  4. Replies: 5
    Last Post: 06-12-2007, 02:18 PM
  5. Assign Character Arrays data from an STL Container
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 12-05-2001, 10:33 AM