Thread: Help

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    10

    Help

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <conio.h>
    
    void shuffle( int wdeck[][13]);
    void deal( const int wdeck[][13], const char *wface[],
    	 const char *wsuit[]);
    void pair( int a[]);
    	
    		  
    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};
    
    	srand( time(0));
    
    	shuffle(deck);
    	deal(deck, face, suit);
    
    
    	return 0;
    
    }
    
    void shuffle(int wdeck[][13])
    {
    	int row;
    	int column;
    	int 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;
    	int row;
    	int column;
    
    
    	for ( card = 1; card <= 52
    		
    		
    		
    		
    		
    	; 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 % 52 == 0 );
    					_getch();
    					
    				}		
    			}
    		}
    	}
    }

    Alright guys...this shuffles cards and prints out 52 cards but I have to press a key for each card to print.

    How do I make it print all 52 cards at once?

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Did you not write this? If you wrote it, you would know.
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    It's rather obvious, you have a getchar command at the end of your loop, the loop won't start again until you enter a character.

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    10
    Quote Originally Posted by JFonseka View Post
    It's rather obvious, you have a getchar command at the end of your loop, the loop won't start again until you enter a character.
    I need to move the getchar command so it keeps looping right?

    where would I put it so it loops for the 52 cards at once?

    also, how would I make it break the cards into 4 differant hands?

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Read your code. Write a flowchart. Insert what you want. Read flowchart. Generate code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed