Hello,
I am writing a program where a user enters two integers, a max and a min. From these two values, the program should generate 12 random numbers between those two values (inclusive). So if a user entered 10 and 22, then the answer can be : 10,11,12,13,14,15,16,17,18,19,20,21,22.
Right now I am having some difficulty with just running the program. I am getting an error that says I have too few arguments to function random_generator on lines 20-31 [the block of printf statements]
If someone can help me fix the error and make sure I am getting the random numbers it would be greatly appreciated. Thank you.
Here is the code:
Code:
//Random
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int random_generator(int minval, int maxval);
int
main(void)
{
srand(time(NULL));
int minval, maxval;
printf("Enter min and max integers.");
scanf("%i", &minval);
scanf("%i", &maxval);
printf("Some random integers between %i and %i are:\n", minval, maxval);
printf("%i\n", random_generator());
printf("%i\n", random_generator());
printf("%i\n", random_generator());
printf("%i\n", random_generator());
printf("%i\n", random_generator());
printf("%i\n", random_generator());
printf("%i\n", random_generator());
printf("%i\n", random_generator());
printf("%i\n", random_generator());
printf("%i\n", random_generator());
printf("%i\n", random_generator());
printf("%i\n", random_generator());
}
int random_generator(int minval, int maxval)
{
return (rand()%(maxval - minval )+ minval);
}