Hello. I am working on a Blackjack game and I have a question about maps. If I deal player1 a 10 of diamonds and a 5 of clubs my total needs to be 15 and that value has to come from a map.
Can I add the elements in a map?
Ex.
Map<int,int>MyMap
Assume MyMap [10] = 10; and MyMap [5] = 5;
Will MyMap [10] + MyMap [5] = 15; and if so can I output 15 directly to the screen?
I am new to the site and programming so if this belongs in the Homework section
I apologize.
Thanks
firedraco has answered your question but I am more interested when you design it as map<int,int> MyMap;
Don't you need to store the "value" of Spade, Heart, Club, Diamond somewhere in your map also? Afterall 10 Diamond is smaller than 10 Spade (based on poker game rules).
Thanks for the answer firedraco. I have several maps and stacks to take care of dealing the deck, checking card value, etc.
I have another question about my Blackjack game. I have to keep a running total of cards dealt to each player and I could use some help.
C is the 52 cards and I am using the % operator to pin point the face card.
CardStack is the stack I am pushing the cards on and popping off of when I deal.
num2 = c % 13
switch(num2)
{
case 0:
Rank[0] = 'A';
CardStack.push(Rank[0]);
Total[0] = 1;
TotalStack.push(Total[0]);
break;
I am using a stack (TotalStack) to push the value of the card on and then popping off the stack when I deal but I am having a hard time getting the right value for the right card. I deal a 10 of clubs and a 10 of diamonds to player 1 and his total is 4, not 20.
Should I scrap the TotalStack and use the map and if so some tips would be great.
Thanks