// aug4ex1a.cpp : Defines the entry point for the console application.
// Choose some cards.  Print out count of num of times they were chosen.

#include "stdafx.h"
#include "stdlib.h"
#include "time.h"

void print_card(int);

int main(int argc, char* argv[])
{   int kard, kount;
    int cards [53] = {0};  /*counter for my cards*/

    srand(time(NULL));

	for (kount=1; kount<= 10; kount++) {
		kard=rand() % 52 + 1;
		printf("You drew a ");
		print_card(kard);
		printf("\n");
		cards[kard]++;

	} /* end of for kount */

	printf("\nThe following cards were chosen: \n");

	for (kard=1; kard <= 52; kard++) 
		if (cards[kard])  { /* ie is cards[kard] > 0  */
			print_card(kard);
			printf("chosen %d time(s)\n", cards[kard]);
		} /* end if cards[kard] */

	return 0;
} /* end function main */


// this function prints out a card given a num 1 - 52
void print_card (int card)  {
	int suit, rank;
     
	rank = (card-1) % 13 + 1;
	suit =  (card-1) / 13 + 1;

	switch (rank) {
	  case 1: printf("Ace of "); break;
      case 11: printf("Jack of "); break;
      case 12: printf("Queen of "); break;
	  case 13: printf("King of "); break;
      default: printf("%d of ", rank); break;
	} /* end switch rank */

    switch(suit) {
	  case 1: printf("Hearts "); break;
	  case 2: printf("Clubs ");  break;
	  case 3: printf("Diamonds "); break;
	  case 4: printf("Spades "); break;
	} /* end switch suit */

} /* end function print_card */