Help

This is a discussion on Help within the C Programming forums, part of the General Programming Boards category; 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 ...

  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
    Katy, Texas
    Posts
    2,309
    Did you not write this? If you wrote it, you would know.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  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
    Posts
    23,010
    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

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