#include <stdlib.h>
#include <stdio.h>
void roll_three(int* one, int* two, int* three)
{
int x,y,z;
x = rand()%6+1;
y = rand()%6+1;
z = rand()%6+1;
one = &x;
two = &y;
three = &z;
printf("%d %d %d\n", *one,*two,*three);
}
int main()
{
int seed;
printf("Enter Seed: ");
scanf("%d", &seed);
srand(seed);
int x,y,z;
roll_three(&x,&y,&z);
printf("pai: %d %d %d\n", x,y,z);
if((x==y)&&(y==z))
printf("%d %d %d Triple!\n",x,y,z);
else if((x==y)||(y==z)||(x==z))
printf("%d %d %d Double!\n",x,y,z);
else
printf("%d %d %d\n",x,y,z);
return 0;
}
This the terminal, I type 123 for the seed. However, the printf in roll_three and the printf in main give me different output? Why *one and x are different?
srand()is expecting anunsigned intso suggestmain()start with:unsigned seed; printf("Enter Seed: "); scanf("%u", &seed); srand(seed);