The code compiles fine for me on Dev-C++ 4.9.8.7
I had to add a main() function though, since you apparently forgot it.
However, did you leave out any code?
Try to copy and paste the code snippet, instead of re-writing it.
Here's the code I tested with:
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
int GetRand(int min, int max)
{
static int Init = 0;
int rc;
if (Init == 0)
{
/*
* As Init is static, it will remember it's value between
* function calls. We only want srand() run once, so this
* is a simple way to ensure that happens.
*/
srand(time(NULL));
Init = 1;
}
/*
* Formula:
* rand() % N <- To get a number between 0 - N-1
* Then add the result to min, giving you
* a random number between min - max.
*/
rc = (rand() % (max - min + 1) + min);
return (rc);
}
int main() {
std::cout<<GetRand(10, 20)<<std::endl;
std::cin.get(); //wait for dummy input
return 0;
}