dimanche 26 avril 2015

How can I randomize an array?

Here's the part of the program I'm having problems with:

// precondition: board is initialized
// postcondition: board is shuffled by randomly swapping 20 values
void shuffle(int board[][NCOLS]) {
    int num = rand();
    num = num %6 + 1;
    for (int i = 0; i < 20; i++) {


    }
}

here's a link to the full program: http://ift.tt/1PIphHY

Pretty sure I have it wrong already, I think i may need the rand function but I'm not sure how the for loop would work. Basically there are 6 pictures and they're in 4 columns, it's a memory game and as of the moment they stay in the same place. I need to make it so that they are random and flipped on the side where you can't see them but I can't figure it out. I have no idea how to randomize columns especially when they're under the name of simply board and NCOLS. Please help me, I appreciate any input




Aucun commentaire:

Enregistrer un commentaire