shuffle deck

This is a discussion on shuffle deck within the Game Programming forums, part of the General Programming Boards category; Code: Hi guys! I have created this deck and I want to shuffle it. Could anyone help me shuffle it, ...

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    1

    shuffle deck

    Code:
    Hi guys!
    I have created this deck and I want to shuffle it.
    Could anyone help me shuffle it, and mention any mistakes???
    I have to submit the assingment by tomorrow..
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #define deck_size 52
    
    int main ()
    {
    
    printf("\n --------------------\n");
    printf("| The Game of 31     |\n");
    printf(" --------------------\n\n");
        int z;
        int i,j,x;
        int temp;
        int initial_deck[deck_size];
        int shuffled_deck[deck_size];
        printf("Initial Deck:\n");
        
        for(z=0;z<deck_size;z++)
        initial_deck[z]=z;
        {
        for(i=1;i<14;i++)
        { 
            for (j=3;j<7;j++)
            switch (i)
            {      
            case 1: printf("|A%c|",j);
                    break;
                    printf("\n\n");
            case 2: printf("|2%c|",j);
                    break;
                    printf("\n\n");
            case 3: printf("|3%c|",j);
                    break;
                    printf("\n\n");
            case 4: printf("|4%c|",j);
                    break;
            case 5: printf("|5%c|",j);
                    break;
            case 6: printf("|6%c|",j);
                    break;
            case 7: printf("|7%c|",j);
                    break;
            case 8: printf("|8%c|",j);
                    break;
            case 9: printf("|9%c|",j);
                    break;
            case 10: printf("|10%c|",j);
                     break;
            case 11: printf("|J%c|",j);
                     break;
            case 12: printf("|Q%c|",j);
                     break;
            case 13: printf("|K%c|",j);
                     break;
                           }
              printf("\n");}
           }
    system("pause");
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,266
    Given that this is a homework exercise, and your code does nothing resembling a shuffle, you run into the site homework policy which, essentially, requires you to do your own homework.

    You might want to look up the Fisher-Yates shuffle.
    Right 98% of the time, and don't care about the other 3%.

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,425
    you have spent more time messing around with printf statements than actually thinking of how to provide an answer
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  4. #4
    Registered User Inkinsarto's Avatar
    Join Date
    Apr 2013
    Posts
    34
    Your starting out too complicated. I would recommend starting simple, and build up the program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to shuffle the buttons in MFC
    By cool friend in forum Windows Programming
    Replies: 1
    Last Post: 12-30-2009, 03:57 PM
  2. Shuffling a deck?
    By Neo1 in forum C++ Programming
    Replies: 23
    Last Post: 07-16-2007, 01:21 AM
  3. Array Shuffle
    By ypramesh in forum C Programming
    Replies: 2
    Last Post: 04-08-2006, 11:01 AM
  4. Deck Shuffle
    By pjharris in forum C++ Programming
    Replies: 51
    Last Post: 01-06-2006, 03:59 PM
  5. a shuffle program
    By *Tim* in forum C Programming
    Replies: 7
    Last Post: 11-17-2002, 10:59 AM

Tags for this Thread


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