deadlyapp
Diamond Member
Alright, so currently working on an assignment that has me making a deck of cards, shuffling those cards, and manipulating it in a couple of ways. I've finished all that part but I also need to build a function that displays the remaining cards in the deck. There is also a parameter passed to this function on how many cards to display per row.
Here's the information:
my current code looks like this:
where the hasNextCard function tells me whether or not I have another card. If I don't it exits with "empty deck".
I simply can't think of a way to be able to manipulate how many I print in each row though. I'm sure it's something trivial.
Thanks for any help that anyone can give me.
Here's the information:
Code:
/* Displays the name and suit of all undelt cards in a deck to the console using
* printf (see samples below). The cards are displayed in the order they occur
* in the deck (lowest undelt index first). The specified number of cards are
* shown on each line, if possible. The cards are separated by a comma-space
* but the last card in a row does not have a comma-space. In addition, there is
* a newline, '\n', printed after the last row. If there are no undelt cards in
* the deck the method prints "Empty Deck" with a '\n'. Note that there are no
* spaces or characters of any kind displayed before the first card in a row or
* the Empty Deck message.
*
* Sample Output (52 undelt cards, 13 specified for cardsPerRow):
*
* See comment for newDeck() above.
*
* Sample Output (9 undelt cards in the deck, 7 specified for cardsPerRow):
*
* 4D, KH, 9C, 2C, 3D, QS, 3S
* 5H, XD
*
* Sample Output (5 undelt cards in the deck, 9 specified for cardsPerRow):
*
* 7S, KD, JH, 2H, 8C
*
* Sample Output (zero undelt cards in deck, N specified for cardsPerRow):
*
* Empty Deck
*
* param cardsPerRow: The number of cards to show per row.
*/
void displayDeck(int cardsPerRow);
my current code looks like this:
Code:
void displayDeck(int cardsPerRow)
{
int i;
if (hasNextCard)
{
for (i = 0; hasNextCard(); i++)
{
printf("%c%c, ", deck[i].name, deck[i].suit);
}
}
else
{
printf("Empty Deck\n");
}
}
where the hasNextCard function tells me whether or not I have another card. If I don't it exits with "empty deck".
I simply can't think of a way to be able to manipulate how many I print in each row though. I'm sure it's something trivial.
Thanks for any help that anyone can give me.