Completely new to C++. Programmed selection sort on 1D array of arbitrary length. Want to allow user to keep inputting integers into console to make an array of desired length, to be subsequently sorted.
Can only seem to make arrays of length 2 using a while loop for adding elements. Code and example of erroneous result when inputting 6, 2, 3, and 9 shown below.
Script:
// Preprocessor directives and namespace declaration
#include <iostream>
#include <vector>
using namespace std;
// Function
void SelectionSort(int *arr, int len)
{
    // Loop through index j in arr
    for (int j = 0; j < len; j++) {
        
        // Assume element j is minimum, and initialise minIndex
        int min = arr[j];
        int minIndex = j;
        
        // Loop through comparisons to determine actual minimum
        // (of elements after and including j)
        for (int i = j; i < len; i++)
        {
            if (min > arr[i])
            {
                min = arr[i];
                minIndex = i;
            }
        }
        
        // Swap minimum with element j
        int temp = arr[j];
        arr[j] = min;
        arr[minIndex] = temp;
    }
    // Display resulting array
        for (int i = 0; i + 1 < len; i++)
        {
            cout << arr[i] << ", ";
        }
        cout << arr[len - 1] << endl;
}
// Main
int main()
{
    // Explain program to user
    cout << "Sort 1D array of user-inputted length/contents" << endl;
    cout << "To finish array, enter -999" << endl;
    
    // Initialise dynamic array
    vector<int> vDyn (1);
    vDyn[0] = 0;
    cout << "Enter first element of array: ";
    int firstElement = 0;
    cin >> firstElement;
    vDyn[0] = firstElement;
    
    // Loop to define elements until desired length reached
    bool keepGoing = true;
    while (keepGoing == true)
    {
        cout << "Enter another element: ";
        int newElement = 0;
        cin >> newElement;
        if (newElement != -999)
        {
            vDyn.push_back(newElement);
        } else
        {
            keepGoing = false;
        }
    }
    
    // Convert vector to array (dynamic to static)
    int* v = &vDyn[0];
    // Get array length
    int len = sizeof(v) / sizeof(v[0]);
    
    // Run SelectionSort function
    SelectionSort(v, len);
    
    return 0;
}
Terminal:
Sort 1D array of user-inputted length/contents
To finish array, enter -999
Enter first element of array: 6
Enter another element: 2
Enter another element: 3
Enter another element: 9
Enter another element: -999
2, 6
 
     
    