I am trying to create a blackjack deck of cards (blackjack uses five decks... 5*52 = 260) Suit is irrelevant in blackjack.

How do I create my deck?

#include <iostream>

using namespace::std;

int main()
{
    char thedeck[13]={'2','3','4','5','6','7','8','9','0','J','Q','K','A'};
    char deck[260];
    
    for (int i=0;i<20;i++)
    {
        for (int j=0;j<13;j++)
        {
        thedeck[j];
        }
    }
    
    cout << deck;
    system("PAUSE");
return 0;
}

:eek:

Looks like a decent start. You just need to find a way to get the correct subscript into 'deck' to assign values in the inner loop, and then figure out how to shuffle the deck. The simplest way to do the last part is probably std::random_shuffle.

You might also consider adjusting your algorithm to use a single for loop (running 260 times); you could use the modulus operator to cycle through the elements of 'thedeck'

I tried this, but it does not see to get me anywhere. The code compiles what I like to call "a bunch 'o crapply-ola"

#include <iostream>

using namespace::std;

int main()
{
    char cards[13]={'2','3','4','5','6','7','8','9','0','J','Q','K','A'};
        
    for (int i=0;i<20;i++)
    {
        cards[i];
        
    }
    
    cout << deck;
    system("PAUSE");
return 0;
}

What was wrong with your first technique? It looked fine to me.

Though i dont know what exactly blackjack is but i think this is wat u want.

#include <iostream>
using namespace::std;

int main()
{
    char cards[13]={'2','3','4','5','6','7','8','9','0','J','Q','K','A'};
    char deck [260] ;    
    for (int i=0; i< 260; i++)
         deck[i] = cards [i % 13];        
        
    for (int i = 0; i < 260; ++i)
        cout << i << "  " << deck [i] << endl;

    cin.get () ; // use this funciton for making the screen stop
    //system("PAUSE"); dont use OS functions
    return 0;
}

Sorry if this is not what you were looking for.

commented: nice! +1
Member Avatar for iamthwee

I've seen a good class designed for a deck of cards in previous threads.
Do a search.

If you're unfamiliar with classes I would recommend reading up on them. They're quite useful once you get your head around them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.