0

hi,

I wanted to know how to generate random characters, but more specifically , only A,Q,K,J. This will be for a blackjack game program.

5
Contributors
9
Replies
11
Views
8 Years
Discussion Span
Last Post by dmanw100
0

All this expert and no answer?

how about this can i somehow define a literal string with A,J,Q,K,J?
then pick it out of that or something?

1

All this expert and no answer?

There's no reason to say stuff like this. It just antagonizes people.

how about this can i somehow define a literal string with A,J,Q,K,J?
then pick it out of that or something?

Create a character array:

char cards[] ={'J', 'Q', 'K', 'A'};

Generate a random number from 0 to 3 and use it as the array index of cards .

Votes + Comments
I agree, I just lost interest in helping the self-important "me me me" OP
0

Thanks, and I am sorry for the uneeded comment. I have another question. Is there a way to insert arry[]={1,2,3...10,J,Q,K,A}

how about using a templete?

0

There are alot of people that ask about card games and black jack on these forums. Why don't you search the forum and have a look over other threads solving common problems...also you can look at some example code to help you.

Chris

0

There are alot of people that ask about card games and black jack on these forums. Why don't you search the forum and have a look over other threads solving common problems...also you can look at some example code to help you.

Chris

Than You

0

Hehe, don't force an open door:

"AQKJ"[rand()%4]

About {1,...,10,A,Q,K,J} question: are you sure that "10" is a character? Or TWO characters? ;)

0

Hehe, don't force an open door:

"AQKJ"[rand()%4]

About {1,...,10,A,Q,K,J} question: are you sure that "10" is a character? Or TWO characters? ;)

ya i know its not a character, but I guess there is no way to make a array with both character & array. Does vector work in this way?

0

ya i know its not a character, but I guess there is no way to make a array with both character & array. Does vector work in this way?

Make an array of strings then:

string cards[] ={"10", "J", "Q", "K", "A"};

Pick a random number from 0 to 4 (or 0 to 12 or however many cards you have, 0 to 12 if you are using all of them now - add those cards to the array above) and put it an index integer variable and return cards[index] like I mentioned in my earlier post. Or you can not even create the variable and just do it like ArkM did:

cards[rand () % 13];
0

Why not use numbers (1-13) and convert 1, 11, 12, 13 to Ace, Jack, Queen, King when you output?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.