One thing I see wrong at a glance is that you are dereferencing myShare as an array, but you are calling delete shares; instead of delete[] shares;
An object created with new must be destroyed with delete.
An object created with new[] must be destroyed with delete[].
But that issue is not specific to purchaseShares. Can you use a debugger and tell us exactly which line is generating the error?
Showing more code might help (like showing loadData and getCompanyName), but what would help more is if you copied your code into another project, and then whittled down the code to create a minimal example that we can compile to reproduce the problem.
PS: Unrelated to your actual issue, but you should avoid using the exit() function. If you desire to return from main, either just put nothing down (it will automatically return 0), or write return 0; This allows any automatic object destruction to still run gracefully.
I will run the deubugger now and get back to you. I am a begginer so all of this is pretty new to me. I began learning to with CodeBlocks and now my university forces us to use Atom on a virtual machine which hasnt been the easiest transition.