-
Change Value in an array
I want to change the value in an index of an array
I have partially posted the code where I am having problems with:
[code]
array[6]={2.02,2.05,3.20,3.28,5.0,5.0};
float score;
if (score!=array[selection1])
{
score=array[selection1];
}
[\code]
What I am trying to do is to change the appropriate value in the array with the value in score.
e.g. if score was entered as 3.0 and was replacing 2.05, how do you get the program to change the 2.05 value in the array?
Thank for any help
-
Couple of points:-
Code tags end with [/code], not [\code] :p
You should declare array as:-
float array[6] = {2.02,2.05,3.20,3.28,5.0,5.0};
What type is selection1?
Remember, indexes in C range from 0 to n-1, where n is 6 here.
-
>score=array[selection1];
This assigns the value of the element of array with index selection1 to score. This
array[selection1] = score;
assigns the value of score to the element of the array with index selection1.
-
Thanks for the advice there lads.........however I just got it to work