Okay, there's obviously some code missing. You don't have enough of your main() shown -- the curly braces don't match up before you define (implement) your deck functions.
Also, it appears you're programming in C, not C++. If you were programming in C++, you should have a Deck object that makes use of some sort of List container object for holding your Card objects. On to business:
You are mixing up variable names with 'numshuffle' and 'numbershuffle'.
This code makes little sense:
Quote:
quote:
while (numshuffle < 0)
{
if(numbershuffle < 0)
{
printf("Error: negative");
}
else
{
shuffleDeck(list[0], numshuffle); // calls splitDeck and mergeDeck
}
}
|
... for a couple reasons. First of all, if numshuffle is negative, then it the while loop will NOT execute, so your if() statement is clearly never going to be executed. It's impossible. Next, you don't ever modify numshuffle, so your loop will iterate infinitely.
Now let's take a look at your deck manipulation algorithms.
Splitting a deck should be a simple matter of identifying the first card of each half of the deck. It shouldn't really require a lot of mathematics. After shuffling the deck, your first card shouldn't change. (That's why dealers have to cut the deck, by the way.) Cutting the deck splits the deck at some random place, and puts the top half on the bottom. Note that this deck split is different than what's required for a perfect shuffle -- a perfect shuffle should divide the deck into equal halves.
If you look through your code, you malloc memory all over the place, and you do it inside of loops (so you do it a lot). You never, however FREE this memory.
You're always dealing with the same deck, so why are you continually allocating memory for new cards? You don't ever create new cards, you only reorganize the ones that already exist. There should be NO malloc involved.
Is it your assignment to learn how this program works, or to write your own??
Take care,
Nik
http://www.bigaction.org/