I need to write a program that will prompt the user to input a number-sided dice and a number of rolls, and then it will output all of the rolls in a sequence. The program I have written will get the number of rolls correct, but something goes wrong with the number-sided dice. It will output numbers in the 100s for a 6-sided dice. Here's my code, does anyone know how to fix this? (My 'y' integer is the one for the number sided die).
Code:
#include <stdio.h>
#include <time.h>
int rolldie();
int main(){
int x, n;
double y;
printf ("What sided dice do you want to roll?... %d");
scanf ("%d", &y);
printf("How Many Rolls do You Want?... %d");
scanf("%d", &n);
srand(time(0));
for(x=0;x<n;x++)
printf("%d ",rolldie());
return 0;
}
int rolldie(){
return 1 + rand() %'y' ;
}
Comment