Your second while loop in pregame() will be infinite if it has to restart, since the results of the calculation will be the same every time through. Does it need to go back to the top of the _first_ while loop if there are duplicate ranks?

What you could do to track the source of the money appearing is at each statement that modifies the variable that unexpectedly increases, print a debug statement that displays the current money, the money added and the result, and why. There are several money variables and you don't say which one has the wrong value, so for example if it's ......


int card[6];
card[6] = ((rand() % 52) + 1);

That could be the problem. If you declare int card[6], the size of the card array is six, starting at zero, so (count them) the elements are 0,1,2,3,4 and FIVE as the last one. So you have undefined behaviour whenever you write to card[6] (same goes for the other two arrays). This is the infamous buffer overrun bug. If the game uses 7 cards, you need to declare the arrays to have 7 elements, e.g. int card[7]; which will give you elements (count them again) 0,1,2,3,4,5 and SIX.

Don't be tempted to declare arrays one too large and use elements 1-7, ignoring zero. It's a bad habit. If I ever do this I end up confusing the hell out of myself; I end up with a program where some arrays are zero based and some are 1 based, and I end up with silly +1's and -1's everywhere, and it's a source of lots of irritating bugs. If the user wants to count from 1 instead of zero, that's a user interface issue and should be dealt with at the user interface ONLY; those +1's should NOT be allowed to trickle down into the program logic. Convert from 1-based to 0-based when the user enters data, and convert from 0-based to 1-based when you display results.