Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4049088
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:54:00+00:00 2026-05-20T13:54:00+00:00

I am trying to create a poker game with 2 players, each get 5

  • 0

I am trying to create a poker game with 2 players, each get 5 cards. The issue I am having is that when the first player draws his 5 cards, the second player draws the same 5 cards too. in Deck, there’s a variable top_card that decrements every time for a draw. but it resets back to 51 rather then continuing from 46. Can anyone help me?

 Sample output
 nine of clubs 
 jack of diamonds 
 queen of clubs 
 queen of hearts
 joker of hearts

 nine of clubs 
 jack of diamonds 
 queen of clubs 
 queen of hearts
 joker of hearts
//Card 
#include <string>
using namespace std;

enum suits { none, diamond, club, heart, spade };

class card {
public:
    card( ){
        suit = none;
        rank = 0;
    }   
    card( suits sv, int rv) {
        rank = rv;
        suit = sv;
    }

    int spots ( ){
        return rank;
    } 
    suits kind ( ){
        return suit;
    }

    string toString() const {
        return rankString(rank) + " of " + suitString(suit);
    }

    string rankString(int r) const{
        if (1 == r)       return "ace";
        else if (2 == r)  return "two";
        else if (3 == r)  return "three";
        else if (4 == r)  return "four";
        else if (5 == r)  return "five";
        else if (6 == r)  return "six";
        else if (7 == r)  return "seven";
        else if (8 == r)  return "eight";
        else if (9 == r)  return "nine";
        else if (10 == r) return "ten";
        else if (11 == r) return "jack";
        else if (12 == r) return "queen";
        else if (13 == r) return "king";
        else return "joker";
    }

    string suitString(suits s) const {
        if (s == spade)         return "spades";
        else if (s == heart)    return "hearts";
        else if (s == diamond)  return "diamonds";
        else if (s == club)     return "clubs";
        else                    return "non-suit";
    }

protected:
    int   rank;
    suits suit;
};


//Deck
#include "card.h"
#include <ctime>
#include <cstdlib>
using namespace std;

class deck {
public:
    deck() {
        top_card = 0;
        for( int i = 2; i <= 14; i++ )
        {
            card c1( diamond, i ),
                c2( spade,   i ),
                c3( heart,   i ),
                c4( club,    i );

            cards[ top_card++ ] = c1;
            cards[ top_card++ ] = c2;
            cards[ top_card++ ] = c3;
            cards[ top_card++ ] = c4;
        }
    }    

    void shuffle() {
        srand(time(NULL));
        for(int i=0; i<52; i++) {
            int a = rand()%52;
            card temp = cards[i];
            cards[i] = cards[a];
            cards[a] = temp;
        }
    }

    bool is_empty() {
        return (top_card <= 0);
    }

    card draw() {
        if( !is_empty() ) {
            return cards[ --top_card ];
        } 
        else {
            card non_card( none, 0 );
            return non_card;
        }
    } 

protected:
    card cards[ 52 ];  
    int top_card;     
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T13:54:01+00:00Added an answer on May 20, 2026 at 1:54 pm

    You pass your deck in by value, so the hand decrements the top_card variable for a copy of the deck. Pass it in by reference.

    hand(deck & a) { <-- CHANGE HERE
            for(int i=0;i<5;i++)
                hands[i] = a.draw();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm trying to create a simple multi-threaded game engine for the game I
Im learning basic C on my own and trying to create a poker client.
I am trying to create a model instance that includes a list of model
I have been trying to create a simple application that will let the user
I'm trying to create a scheduled task that updates less than 5% of the
I am trying to create a database table for my game, and would like
I am trying to clear up an issue that occurs with unflushed file I/O
I'm trying to get Lighttpd up and running, but I'm having a few issues
I am actually trying to create an application for Window Phone that could create
I am trying to create a table that was dropped previously. But when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.