What is wrong with this code?? I am supposed to take the min and max in RandRange and the return should be the random no. b/t min and max using (rand() % (1 + max - min) + min).
#include <iostream>
#include <ctime>
using namespace std;
int RandRange(int min, int max);
int main()
{
int min, max;
srand((unsigned int)time(0));
cout << "Enter your min value" << endl;
cin >> min;
cout << "Enter your max value" << endl;
cin >> max;
int RandRange = (rand() % (1 + max - min) + min);
for (int j = 0; j < 10; j++)
{
for (int i = 0; i < 10; i++)
{
cout << RandRange << "\t";
I am supposed to take the min and max in RandRange and the return should be the random no.
On line 06, you use the function prototype RandRange, but you never define the function. Instead, you define and declare as a variable on Line 18. I could be wrong,
but according to the instructions, I would expect RandRange as a function with a
return value of the random number. If I am correct, then I recommend you to define
the function int RandRange(int min, int max).
#include <iostream>
#include <ctime>
usingnamespace std;
int RandRange(int min, int max);
int main()
{
int min, max;
srand((unsignedint)time(0));
cout << "Enter your min value" << endl;
cin >> min;
cout << "Enter your max value" << endl;
cin >> max;
cout << "The random number is " << RandRange(min, max) << endl;
//int RandRange = (rand() % (1 + max - min) + min);
//for (int j = 0; j < 10; j++)
//{
//for (int i = 0; i < 10; i++)
//{
//cout << RandRange << "\t";
//}
//cout << endl;
//}
}
int RandRange(int min, int max)
{
//Define the random function here
//return the random number
}