I'd like the user to be able to input a range for the array, I've made it able to be set to a high, but I don't know how to set the low
i.e:
right now you can set 20 and it'll print 1-20
but I want it to print (for example) 7-20, or 13-20, etc etc
//Brandon Thomas
# include<iostream>
usingnamespace std;
int main()
{
srand(time(0));
//H/L Variables
int a, b;
//Instructions
cout << "Please enter high and low of array" << endl;
//Sets Length of the Array (ie. A = 20, 0-20 is generated)
cin >> a;
//Sets lowest number to appear on screen
cin >> b;
//Sets the rising counter to the lowest number
int counter = b;
system("CLS");
//Sets the Array to A (Length)
int y[a];
//Loads Numbers into Array
for(int loop = 0; loop <= a-b; loop++)
{
//Loop is position in Array, so starts at 0
//Counter is equivalent to the Low, so I'll use 4 as example
y[loop] = counter;
counter++;
}
//Shuffles numbers within the Array
int z = sizeof(y)/sizeof(y[0]);
random_shuffle(y, y+z);
//Prints shuffled numbers
for(int x = 0; x < z; x++)
{
cout << y[x] << endl;
}
system("PAUSE");
}
If you have, say, N%10 where n is any number, it means that you can have the values 0 through 9. That is because you would have 0 as a remainder, after you divide n by 10, or you can have up to 9 as a remainder. For example, 13%10 gives you 3, 19%10 returns 9, 20%10 returns 0, etc.
In general, if you have the expression: a+N%b, where a, b are constants and N is a variable integer, then you have a minimum value of (b-a) and a maximum value of (a+b)-1.
example: 6+N%12
a = 6, b = 12
min: 6
max: 17
Double check this- its late where I live and im quite tired
Edit: I think i may have misunderstood what you're trying to do. Can you explain exactly what it is youre doing?
-Generate Numbers based off user input
-Have them outputted in a random order
-User Input selects range of the numbers to be output: (Low and High)
-No 2 numbers can be repeated
Try running the program I have right above your most recent post, first try the Input
20 (enter) 1
it prints the numbers 1-20 in a random order without any repeats
then try the input
20 (enter) 10
It's doesnt print 1-9 (as it's told) but instead of printing 1,2,3,4,5,6,7,8 and 9, it prints garbage in place of those integers