Change Value in an array

This is a discussion on Change Value in an array within the C Programming forums, part of the General Programming Boards category; I want to change the value in an index of an array I have partially posted the code where I ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    7

    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

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,266
    Couple of points:-

    Code tags end with [/code], not [\code]

    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.

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    >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.

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    7
    Thanks for the advice there lads.........however I just got it to work

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-25-2008, 12:50 AM
  2. I thought I understood but....(pointer question)
    By caroundw5h in forum C Programming
    Replies: 1
    Last Post: 02-22-2005, 02:05 AM
  3. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:27 PM
  4. grow function to change size of array class
    By Santos7772002 in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2002, 04:31 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21