Pick random array index and change the element value
Supposin' you have an array
Also supposin' you want to randomly pick an index in that array and set the element of that random index to the value of 5.
Now, simply print out the number of the changed index and:
you then want to add up all the elementsof the changed array to get the sum.
index 3 was randomly picked. the value of index 3's element is changed from 4 to 5.
When ran, the program then displays :
4 - 57
for the life of me i can't seem to find out how to choose a random index and manipulate its element.
I don't have any useful code for this so far, because i simply can't get past this whole 'random index' business.
Any help is greatly appreciated.
Sorry. i'm fairly new to this stuff
I thank you all for your help.
the problem i had with the 'yourarray[randnum] = 5;' was that the compiler gave me an 'incompatible types' error.
i searched high and low to find out what i was doing wrong, but in the end, i simply gave up.
I'll definitely try Subith86's solution.
I'm not trying to be deliberately vague. the very heart of my little program is getting this random index operation going. until i do, i have no useful code to show all of you.
Thank you again for your help and patience.