samedi 23 juillet 2016

Using rand function in C [duplicate]

This question already has an answer here:

Hey guys I'm doing my assingment but I stuck with this rand() function I'm rolling dice with this function for 2 players in order to determine who will start first. but it always give the same number for both of them I dont know why I tried adding another rand function but result was the same, can some one help me with it ?

int bunco_starts()
{
    int p1roll=0, p2roll=0;
    printf("Dice are rolled by each player in order to select who will start first:\n");
    p1roll=roll_a_dice();
    printf("%d\n", p1roll);
    p2roll=roll_a_dice2();
    printf("%d\n", p2roll);
    printf("Dice 1 (rolled by player 1): %d  Dice 2 (rolled by player 2): %d\n", p1roll, p2roll);




}
int roll_a_dice()
{

    return 1+rand()%6;

}




Aucun commentaire:

Enregistrer un commentaire