Before you access num, you need to be sure that the vector contains at least two elements.
At line 14, if the user enters a positive integer, it is stored in the vector. Then the loop terminates, containing just one element. Under that condition, you will get an error when accessing the second element.
while ( d < 2)
cin >> another_variable_that_it_is_not_the_counter_of_the_loop;