I am working on an assignment for school and I'm stuck.
Generate 50 non-repeating numbers between 1 - 1000. Then, sort numbers using a bubble sort. Then sort the same numbers using an insertion sort. I've generated my random numbers using a for loop, but when I try to access the array outside of the for loop it only contains the last random number...HELP!!!
Well I've tried it with p[0] and get the same output, if I use p[1] or above I get 0's. I have never used arrays in C++ before. It seems that my for loop is only replacing the first element in the array after each itteration. Any suggestions on how I can get it to store each element in a different location after each itteration?
No really, read your code. Really think about what it does. Pretend you are a computer executing that program, and see what result you will get. I am sure you can find your mistake on your own.
and now it will print the first number generated instead of the last, I can also go through use p[1], p[2], and so on to get the corresponding element, but I still can't seem to figure out how to print all the elements at once outside the loop. I'm sure that I'm making this harder than it is, but I am really just struggling here.