Multivariable issues

This is a discussion on Multivariable issues within the C Programming forums, part of the General Programming Boards category; Hello, I have a program that randomly shuffles cards. Within the switch/case statements I am trying to display 'T' as ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    15

    Multivariable issues

    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));
    }

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,652
    Well, the variable 'c' is just a single character (or rather, an int being used as one). If you need more than that, use an array...
    Code:
    #include <ip.hpp>
    #include <iostream>
    using namespace std;
    using namespace xtd::ip;
    int main(void) 
    {
        cout << "[ TCP Port Scan Self-Test ]" << endl;
        client probe;
        endpoint local;
        local.address = "127.0.0.1";
        local.protocol = IPPROTO_TCP;
        for(local.port = 0; local.port < (1 << 16); ++local.port)
        {
            if(probe.open(local))
                cout << "Listening: ";
            else
                cout << "No Response: ";
            cout << local.port << endl;
        }    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I hate pointers or Pointer Issues
    By bolivartech in forum C Programming
    Replies: 9
    Last Post: 11-14-2009, 10:48 AM
  2. Serious template issues (!!!)
    By Mikal in forum C++ Programming
    Replies: 2
    Last Post: 07-23-2009, 08:46 AM
  3. issues in float division a/b
    By George2 in forum C# Programming
    Replies: 17
    Last Post: 04-24-2008, 06:15 AM
  4. Bitmap scroll issues
    By Gerread in forum Windows Programming
    Replies: 4
    Last Post: 05-14-2007, 05:18 AM
  5. hexdump issues
    By daluu in forum C Programming
    Replies: 2
    Last Post: 03-04-2003, 08:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21