Hello Thanks in advance for your interest.
I am trying to make a standard deck of 52 playing cards.
And below is the output that I want to create.
=================================
Initialized Deck:
0: AC 13: AD 26: AH 39: AS
1: 2C 14: 2D 27: 2H 40: 2S
2: 3C 15: 3D 28: 3H 41: 3S
3: 4C 16: 4D 29: 4H 42: 4S
4: 5C 17: 5D 30: 5H 43: 5S
5: 6C 18: 6D 31: 6H 44: 6S
6: 7C 19: 7D 32: 7H 45: 7S
7: 8C 20: 8D 33: 8H 46: 8S
8: 9C 21: 9D 34: 9H 47: 9S
9: TC 22: TD 35: TH 48: TS
10: JC 23: JD 36: JH 49: JS
11: QC 24: QD 37: QH 50: QS
12: KC 25: KD 38: KH 51: KS
====================================
and this is a part of my code that has a problem.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
static const unsigned short VALUE = 13;
static const unsigned short SUIT = 4;
static const std::string VALUES[VALUE] = { "Ace","2","3","4","5","6","7","8","9","Ten","Jack","Queen","King" };
static const std::string SUITS[SUIT] = { "Clubs","Diamonds","Hearts","Spades" };
void load(std::string deck[], const unsigned short SIZE)
{
for (unsigned short i = 0; i < SUIT; ++i)
{
for (unsigned short c = 0; c < VALUE; ++c)
{
deck[i*VALUE+c] = VALUES[c]+SUITS[i][0];
}
}
}
|
But It outputs like this
==========================
Initialized Deck:
0: AceC 13: AceD 26: AceH 39: AceS
1: 2C 14: 2D 27: 2H 40: 2S
2: 3C 15: 3D 28: 3H 41: 3S
3: 4C 16: 4D 29: 4H 42: 4S
4: 5C 17: 5D 30: 5H 43: 5S
5: 6C 18: 6D 31: 6H 44: 6S
6: 7C 19: 7D 32: 7H 45: 7S
7: 8C 20: 8D 33: 8H 46: 8S
8: 9C 21: 9D 34: 9H 47: 9S
9: TC 22: TD 35: TH 48: TS
10: JackC 23: JackD 36: JackH 49: JackS
11: QueenC 24: QueenD 37: QueenH 50: QueenS
12: KingC 25: KingD 38: KingH 51: KingS
=========================================================
So I want to display only the first letter of the values so that I can make it look just like the output example.
but if I make a change like below
1 2 3 4 5 6 7 8 9 10 11
|
void load(std::string deck[], const unsigned short SIZE)
{
for (unsigned short i = 0; i < SUIT; ++i)
{
for (unsigned short c = 0; c < VALUE; ++c)
{
deck[i*VALUE+c] = VALUES[c][0]+SUITS[i][0];
}
}
}
|
it outputs garbage like this
Initialized Deck:
0: ? 13: 2 26: ; 39: ]
1: 1 14: 4 27: 2 40: [
2: x 15: 6 28: 3 41: p
3: y 16: @ 29: ; 42: [
4: z 17: ! 30: ] 43: p
5: d 18: @ 31: 2 44: [
6: p 19: # 32: 1 45: 2
7: a 20: $ 33: 2 46: y
8: s 21: ^ 34: 1 47: 5
9: e 22: ^ 35: 6 48: d
10: ? 23: 1 36: ] 49: a
11: ; 24: 2 37: s 50: b
12: ^ 25: 5 38: , 51: '
=========================================================
Why is it like this ?
I am sorry I did my best trying to describe my problem clearly and shortly
but it still seems messy..
Please feel free to ask me questions if you don't understand my problem..
Thanks!