Another way to initialize our hand is with a function. When given a card as an input parameter to an addCard() function, we need to make sure we put it in the correct place in our hand. The function is as follows:
struct Hand addCard( struct Hand oldHand , struct Card card ) {
struct Hand newHand = oldHand;
switch( newHand.cardsDealt ) {
case 0:
newHand.c1 = card; newHand.cardsDealt++; break;
case 1:
newHand.c2 = card; newHand.cardsDealt++; break;
case 2:
hewHand.c3 = card; newHand.cardsDealt++; break;
case 3:
hewHand.c4 = card; newHand.cardsDealt++; break;
case 4:
hewHand.c5 = card; newHand.cardsDealt++; break;
default:
// Hand is full, what to do now?
// ERROR --> Ignore new card.
newHand = oldHand;
break;
}
return newHand;
}
In the preceding function, addCard(), oldHand, and card are inputs to the function. Remember that variables, including...