The current code, that I've given in the previous post, sorts the numbers vector in descending order -- as your assignment
seems to ask.
You might want to change:
int randomInt = rand() % 20 + -10;
to
int randomInt = rand() % 21 + -10;
... if you want to include the number 10 as possible numbers.
In this regard, your original code with
lowest
and
highest
boundaries was better, because you had better control over the min/max limits.
Also suggest using
at().
1 2 3 4 5 6 7 8
|
while (true)
if (numbers.at(index) == numbers.at(index-1))
index++;
else
{
second = numbers.at(index);
break;
}
|
Finally, not to scare you, but you'll be in a little trouble if you actually
were required to write your own sorting function. Be mentally prepared for that possible moment, and to defend the usage of
std::sort(), which is what a proficient C++ programmer would use.