First of all, please use proper indentation, like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
int main()
{
int random_integer;
int random_size = 10 + rand()%5;
cout <<"Generating " << random_size << "random numbers" << random_size << " (is a random number between 10 to 15).";
for(random_size) { //
random_integer = 20 + rand()%30; // Random number between 20 and 50
cout << random_integer <<", ";
}
return 0;
}
|
It's not much work and will make the code easier to read for you and others. I almost overlooked your for statement.
In C++, the for loop should look like this:
1 2 3
|
for(int i = 0; i < random_size; i++) {
// do stuff
}
|
This is equivalent to
1 2 3 4 5
|
int i = 0;
while(i < random_size) {
// do stuff
i++;
}
|
A few additional things:
1. Output style: You might want to use new lines after the "Generating..." message.
Also in the for loop, you could add a
if (i != random_size - 1)
condition for the comma output, to prevent the comma after the last digit.
2. A little variation, that might be useful for you soon: the for-each loop. If you have an iterable (a vector, an array etc.) you can do
for (element : iterable) {..}
to go over all elements in the vector or array.