Problem with code

I am trying to generate a random number between two numbers that the user gives me. I can't figure it out and am a noobie, can someone explain what is wrong with this code?

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

void rand_int(const int &min, const int &max, int &val);

int main()
{
const int min;
const int max;
int val;

cout << "Please insert your minimum number" << endl;
cin >> min >> endl;
cout << "Please insert your maximum number" << endl;
cin >> const max >> endl;
rand_int(min, max, val);

cout << "Your random numbers are: " << val << endl;


return 0;
}

void rand_int(const int &min, const int &max, int &val)
{
srand(time(NULL))

val = rand()%(max-min + 1) + min;
}
Because you're min and max variables are parameters that are being sent, and not referential parameters, the "&" is not needed, otherwise they are classified as referential parameters.

Therefore try using:

void rand_int(int min, int max, int &val);
thanks
const variables need to be initialized when they're declared and they can't be modified later on.


srand(time(NULL)) <- needs a semicolon at the end
Topic archived. No new replies allowed.