Array won't change it's values in my class' method

So I'm creating a game of Blackjack. Everything is done, all the logic written out and works, but for some reason the deck won't notice that a card has been taken from it. (Sorry if the code doesn't look visually correct, I wasn't sure how to put it in as text on here) Here's the code for my Deck class:

<
#include "Deck.h"
#include <list>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>

Deck::Deck(int shoe) {
int counter = 0;
this->Shoe = shoe;
for (int i = 0; i < shoe; i++) {
for (int j = 1; j <= 13; j++){
for (int k = 0; k < 4; k++) {
this->FullDeck[counter] = j;
counter++;
}
}
}
}

int Deck::DrawCard() {
int value = 0;
int Random = 0;
do {
Random = rand() % (this->Shoe * 52) - 1;
} while (this->FullDeck[Random] == 0);

value = this->FullDeck[Random];
this->FullDeck[Random] = 0; //Here it should be setting it to 0, but once the function returns the array gets set back to what it was before
return value;
}

Deck::Deck()
{
}


Deck::~Deck()
{
}
>


And my Deck.h file:

<
#pragma once

class Deck
{
public:
Deck();
Deck(int shoe);
int DrawCard();
~Deck();

private:
int Shoe;
int FullDeck[52] = {};
};


>
What is the "shoe"?

You try to put and pull shoe*52 cards into the FullDeck that has room for only 52 cards ...
that leads to undefined behaviour.



I would rather shuffle the deck and deal from top than try try try to pick a random card.
Topic archived. No new replies allowed.