I am new in programming .I need something which can generate random no. I found "rand()" . But it is not generating random values. Please check the following simple code. it always gives roll the first dice : 6 roll the second dice : 6 roll the third dice : 5
Here is the code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int main()
{
int dice1,dice2,dice3,total1,total2;
char prediction[10];
int dice_generator()
{
dice1= (rand()%6)+1;
printf("roll the first dice: %d \n", dice1);
dice2= (rand()%6)+1;
printf("roll the second dice: %d \n", dice2);
dice3= (rand()%6)+1;
printf("roll the third dice: %d \n", dice3);`enter code here`
return 0;
}
dice_generator();
total1 = dice1+dice2+dice3;
printf("final value is = %d\n",total1);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire