I've created a small array to hold integers as a small part of a program, array is a bag I can put integers into and out of (eventually). However when i compile and run it and enter number 32 as my target (bag[0] of my array it also changes bag[5] as well in my output of the array. Obviously it's coded wrong but I can't see where?
Still a beginner but I welcome any suggestions on a better ways to implement my "bag" as well. Here's my code
that may not solve your problem but it was definitely iffy code. And also when you loop through the array to print, why not use a local variable inside of the for statement for n instead of declaring it at the top
Thanks for your prompt replies. The reson why I used target was that I only want the first item found in my sort to change to 100 (100 will later be an item code) if my bag was set to 0 for all empty slots then I will be sorting to find an empty slot and filling it with an item code, if i use cntr all slots recieve the new item code. n has now moved to a local variable (silly mistake). I've tried using a new variable instead of re-using target but I still get it filling other slots, so obviously I didn't quite understand this part of your answer, sorry!