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.
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?
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
.
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?
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
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
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? ;)
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?
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];
Why not use numbers (1-13) and convert 1, 11, 12, 13 to Ace, Jack, Queen, King when you output?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.