Please help! Stuck on card dealing program.

This is a discussion on Please help! Stuck on card dealing program. within the C Programming forums, part of the General Programming Boards category; I am stuck! This isn't running...any help would be greatly appreciated. Thanks! Code: #include <stdio.h> #include <stdlib.h> #include <time.h> void ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    6

    Please help! Stuck on card dealing program.

    I am stuck! This isn't running...any help would be greatly appreciated. Thanks!
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    void shuffle( int [] [13] );
    void deal(const int [] [13], const char *[], const char *[] );
    void countface( int [],const char*[]);
    void countsuit(int [],const char*[]);
    int getface(int);
    int getsuit(int);
    
    int main()
    {
    	const char *suit[4] =
    	{ "Hearts", "Diamonds","Clubs", "Spades"};
    	const char *face[13] =
    	{"Ace","Deuce","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"};
    	int deck[4][13] = {0};
    	int hand[]={5};
    
    	srand( time(0) );
    
    	shuffle( deck);
    	deal(deck,face,suit);
    	countface(hand,face);
    	countsuit(hand,suit);
    
    	return 0;
    }
    
    void shuffle(int wDeck[][13])
    {
    	int row,column,card;
    
    	for (card=1;card<= 52; card++){
    		do{
    			row= rand() % 4;
    			column = rand() % 13;
    		} while(wDeck[row][column] != 0);
    
    		wDeck[row][column] = card;
    }	
    
    }
    void deal(const int wDeck[][13], const char *wFace[],
    		  const char *wSuit[] )
    {
    	int card,row,column;
    
    	for (card=1;card<=5;card++)
    		for (row=0;row <=3;row++)
    			for (column=0;column<=12;column++)
    
    				if (wDeck[row][column]== card)
    					printf("%5s of %-8s%c\n\n",
    					wFace[column],wSuit[row],
    					card % 2 == 0? '\n' : '\t' );
    }
    void countface(int hand[],const char *wFace[])
    {
    	int value,count;
    	int store[13] = {0};
    
    	for (count=0;count<5;count++)
    	{
    		value=getface(hand[count]);
    		++store[value];
    	   if (store[value]==2)
    		   printf("You have a pair!");
    	   else if (store[value]==3)
    		   printf("You have three of a kind!\n");
    	   else if(store[value]==4)
    		   printf("You have four of a kind!\n");
    	}
    }
    void countsuit(int hand[],const char *wSuit[])
    {
    	int value,count;
    	int store[4] = {0};
    
    	for (count=0;count<5;count++)
    	{
    		value=getsuit(hand[count]);
    		++store[value];
    	   if (store[value]==5)
    		   printf("You have a flush!!\n\n");
    	}
    	
    }
    int getface(int Card)
    {
    	return (Card-1)%13;
    }
    int getsuit(int Card)
    {
    	return (Card-1)/13;
    }

    Code tags added by Hammer

  2. #2
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    yoo not being rude but this code look very familier .....
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  3. #3
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    why did u declare hand in the first place whats its role in the game check it..
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  4. #4
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    Code:
    void shuffle(int wDeck[][13])
    {
    	int row,column,card;
    
    	for (card=1;card<= 52; card++){
    		do{
    			row= rand() % 4;
    			column = rand() % 13;
    		} while(wDeck[row][column] != 0);
    
    		wDeck[row][column] = card;
    }	
    
    }
    This is a very bad and slow way to shuffle a deck.

    This is faster way to randomize an array
    Code:
    for (i = 0; i < n; ++i) {
           swap(&A[i], &A[rand() % (n - i) + i]
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [Help] Program : How to validate credit card number
    By kingofdcp in forum C Programming
    Replies: 13
    Last Post: 10-31-2009, 12:58 AM
  2. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  3. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  4. Designing a program to deal out seven card stud poker hands
    By killsthehorse in forum C++ Programming
    Replies: 29
    Last Post: 12-08-2008, 03:03 PM
  5. Program stuck in infinite loop-->PLEASE HELP
    By Jedijacob in forum C Programming
    Replies: 5
    Last Post: 03-26-2005, 11:40 AM

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