I am currently making a random word generator in c++. I can set the maximum range of the number but I don't get how to set a minimum range. The offset (displayed below in the code) int min;
is not working as a minimum value. In fact, it adds up to the maximum value. Is there any way so that the minimum value can be set by the user input?
Source code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int range;
int min;
int max;
cout << "Enter amount of numbers to generate: ";
cin >> range;
cout << "Enter minimum boundary: ";
cin >> min;
cout << "Enter maximum boundary: ";
cin >> max;
cout << "\n";
if(min<0 || max <=0 || range <=0 || max==min )
{
cout << "⚠️Error⚠️ Please try again" << endl;
}
else {
srand((unsigned)time(NULL));
for(int x=1 ; x <= range; x++)
{
cout << "R #"<< x<<": " << min+ (rand()%max) <<endl;
}
cout <<"\n"<< "Total random numbers generated: " << range<< endl;
}
}