num
is never assigned any value in main()
. Instead of just randgen(y);
you need num = randgen( y );
randgen()
is declared as void - if you want to return something (a random integer in this case) you need to declare it as such.
You're passing y
as a parameter to randgen()
before it is assigned any value. So you need to assign something to it. (Another question is that you never use the value y
in randgen()
itself, so why pass it in the first place...)
There is no need to assign the generated value to y
then num
then return that (besides num
not being declared in the function at all) you can just return the generated value.
These are probably the main issues. With all that, here's the version of the code that works and does what you (presumably) want.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int randgen(int y);
int main()
{
int y, num;
y = 5;
num = randgen(y);
cout<<num<<endl;
}
int randgen(int y)
{
unsigned seed = time(0);
srand(seed);
return (rand() % 90)+10;
}