OK, you have a few issues here.
In future, can you be more specific about errors - post the compiler output in full
I imagine this would compile with lots of warnings.
The random function does not put anything into the array a.
There are a number times you use uninitialised variables. Line 18 puts a random number into the first element of the array, but only because the variable is uninitialised, and there is no size of the array specified, so C++11 sets it to 1 because of the brace initialisation . So when the BubbleSort function is called, there is only one element in the array.
The main idea you need to learn is that one cannot specify the size of an array at runtime - it must be a constant specified size at compile time.
And you need to ALWAYS make sure your variables are initialised with something. Try initialising with some value at the same time as declaration. There are situations where this can cause problems, but there is a difference between a wrong answer and a garbage answer. Example answer is 100 instead of 10, versus answer = 17896543 instead of 10. So just think about what initial value a variable is going to have - one that isn't going to cause problems.
So I think you should either have a specified size like
1 2
|
const unsigned SIZE = 10;
int MyArray[SIZE];
|
say, or use a vector.
With vectors you can use the push_back function to put objects into the vector. Read this:
Hope this helps - Cheers.