Your problem is here:
while (leftHalf.getSIZE() > 0 && rightHalf.getSIZE() > 0){
If you have drawn all the cards from leftHalf
but rightHalf
still contains some cards then your cycle ends. In that case your shuffled Deck
doesn't contains all cards.
After that cycle you need for example to implement two cycles like this:
while (leftHalf.getSIZE() > 0)
// Draw all remaining cards from leftHalf
while (rightHalf.getSIZE() > 0)
// Draw all remaining cards from rightHalf
=============================================
Also you can get a "Null pointer access" error here:
d.addCard(draw->getVALUE(), draw->getSUIT());
because draw
can be null.
=============================================
Also here:
for (int l = SIZE; l > 0; l--){
you try to draw too many cards. You can start the cycle from j
instead of SIZE
.
==============================================
Another problem is here:
int probPile = leftHalf.getSIZE()/(leftHalf.getSIZE() + rightHalf.getSIZE())*100;
probPile
is always 0 because you use integer division (e.g. 5/100 is 0 if we use integer division). One of the solution to use
floating-point division. You can convert int
value to double
before division in some way, e.g. by multiplying to 1.0
and then convert the result back to int
:
int probPile = static_cast<int>(leftHalf.getSIZE() * 1.0 /(leftHalf.getSIZE() + rightHalf.getSIZE())*100);
Or you can multiply by 100 before division:
int probPile = leftHalf.getSIZE() * 100/(leftHalf.getSIZE() + rightHalf.getSIZE());