// aug4ex1a.cpp : Defines the entry point for the console application.
// Choose 52 unique cards!!!!

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

void print_card(int);
int print_unique_card(void);

int fresh_cards [53] = {0};

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

    srand(time(NULL));

	for (kount=1; kount<= 52; kount++) {

		printf("You drew a ");
		kard=print_unique_card();
		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 */



// 

int print_unique_card (void) {

    int possible_card;

	do {
		possible_card = rand()% 52 + 1;
	}   while ( fresh_cards[possible_card] > 0 );

     fresh_cards[possible_card] = 1;

	 print_card(possible_card);

	 return possible_card;



} /* end function print_unqiue_card */


// 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 */