I need some help with an assignment for a class I'm in.
Here is the assignment:
Create a simplified 7 card poker game (cards are dealt once, no replacement). Use a vector to store the 52 cards. "Shuffle" the vector and output into a stack. Deal 7 cards to each player from the stack alternating 1 player then the other. Store each player's hand in a list. Use the set of rules below to reorder each players hands to have the best hand starting in the leftmost position and discard 2 cards (remove them from the list). Display each player's hand, the description of what kind of hand they have, and who won.
Royal Flush - Ace, King, Queen, Jack, 10 all of one suit.
Straight- 5 cards in a row of one suit (example 3,4 (example 3,4,5,6,7 of diamonds)
Flush - 5 cards of one suit
Full house - 3 of one value (like 7), two of another (like 2).
Pair - 2 cards of one value (like queens)
Ace High - Ace but no other combinations above
Now here is the code I have started. I have a string array called deck and a for loop that I want to take the card rank and suit from the existing arrays and combine them into each of the 52 spaces in the deck array. For some reason though when I debug my program it stretches all the letters out into their own space within the deck array. Any help is greatly appreciated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
using namespace std;
int main()
{
srand(time(0));
int tempDeck[52];
string deck[52]={};
int i, j;
string suitnames[4]={"Spades", "Diamonds", "Clubs", "Hearts"};
string ranknames[13]={"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
for(i=0; i<52; i++) //Creates a new deck
{
tempDeck[i] = i;
}
for(i=0; i<52; i++) //Shuffles the deck
{
int j = rand() % 52;
int temp = tempDeck[i];
tempDeck[i] = tempDeck[j];
tempDeck[j] = temp;
}
for(i=0, j=0; i<52, j<52; i++, j++) //Assigns all the cards a suit and a rank into the real deck
{
int suitnumber = tempDeck[i] / 13;
int rank = tempDeck[i] % 13;
deck[j] = ranknames[rank] + " of " + suitnames[suitnumber];
}
}
|