Hello, I have a program that randomly shuffles cards. Within the switch/case statements I am trying to display 'T' as "10". But I have tried several different ways to define T and it still will only print T instead of 10. A couple of things I have tried is a printf statement after T. I have tried to define T within the case statement, but nothing seems to work. When I try to compile the program with 10 within the ' ' for case (10), it gives me a multivariable error. Below id my code and I will note the place I would like to change the variable T to 10. Any help would be great! Thanks!
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define DECK 52 //Cards in a deck
#define HEARTS 0x48 //Hearts in hex
#define DIAMONDS 0x44 //Diamond in hex
#define CLUBS 0x43 //Clubs in hex
#define SPADES 0x53 //Spade in hex
int draw_card(void);
void shuffle(void);
int rnd(int range);
void seedrnd(void);
/*
* The cards array is stuck out here in no-man's land
* to make it available to both the shuffle and
* draw_card functions
*/
int cards[DECK]; //Deck of Cards
int main()
{
int x=DECK;
int card;
int c,s;
int T= 0xA;
puts("After shuffling");
shuffle();
/*
* Sift through the entire deck, decrementing
* variable x from 52 down to zero.
*/
while(x--)
{
card = draw_card();
switch((card % 13 ) + 1)
{
case(1):
c = 'A';
break;
case(10):
c = 'T' ; /* I would like to display 10 here instead of T*/
break;
case(11):
c = 'J';
break;
case(12):
c = 'Q';
break;
case(13):
c = 'K';
break;
default:
c = (card % 13 )+'1';
}
/*
* The final printf displays the values
*/
if(card>=0 && card<=13)
s = HEARTS;
else if(card>=14 && card<=26)
s = DIAMONDS;
else if(card>=27 && card<=40)
s = CLUBS;
else
s = SPADES;
printf("% c % c\t",c,s);
if(!(x%4))
putchar('\n');
}
}
/*
* The draw_card routine returns a random
* number from 1 to 52 for each card in the deck
*/
int draw_card(void)
{
int card;
do
{
card=rnd(DECK); //draw card
}
while(cards[card]); //is card drawn?
cards[card]=1; //mark it as drawn
return(card+1); //make it 1 to 52
}
/*
* The shuffle routine does two things:
* It initializes the randomizer and
* It initializes the cards[] array
*/
void shuffle(void)
{
int x;
seedrnd();
for(x=0;x<DECK;x++)
cards[x] = 0;
}
/* Generate a random value */
int rnd(int range)
{
int r;
r=rand()%range; //spit up random num.
return(r);
}
/* Seed the randomizer */
void seedrnd(void)
{
srand((unsigned)time(NULL));
}