>still gives the same error message
Is that all of the code in your program? If so, it's no surprise that the function isn't found as you don't define it. Your code should look something like this:
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
int GetRand(int min, int max);
int main(void)
{
int i, r;
for (i = 0; i < 20; i++)
{
r = GetRand(10, 12);
std::cout <<"Your number is " <<r <<std::endl;
}
return(0);
}
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.
*/
std::srand(std::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 = (std::rand() % (max - min + 1) + min);
return (rc);
}
>And your return 0; is mistake also.
No it isn't. You can enclose an expression with parentheses, they don't do anything in this case and are perfectly legal.