jeudi 27 avril 2017

Getting wrong sum of random number

I am on dice game in which i need to roll the dice 5 times and sum the random number. Everything is working fine but my sum is not according to the random number which i am getting

for (int i = 1; i <= 5; i++)
{
    printf(" %d time dice rolled = %d \n",i, rand() % s + 1);
    x += rand() % s + 1;

}
printf("--------------------------------------Sum is %d", x);

getch();

}

s is the sides of the dice




Aucun commentaire:

Enregistrer un commentaire