Thread: newb question on ARRAYS

  1. #16
    Registered User
    Join Date
    Nov 2005
    Posts
    37
    but if i didn't change it...then it started counting at 0 and ended at 19...i need it to count from 1 to 20..? What do you mean by end of the loop block? I thought you meant, move the x++ to the bottom. I'm sorry...i'm a true newbie...thanks for the help..

  2. #17
    Registered User
    Join Date
    Nov 2005
    Posts
    3
    when you store information in arrays you can go from 1-20, but c++ stores it as 0-19 within the array.

  3. #18
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I did mean to move x++ to the bottom, but that's all you needed to do. You didn't need to change the other stuff.

    Your first attempt at the while loop used indexes 1-20. That is wrong. Your second attempt also uses indexes 1-20, again wrong. The proper indexes for a 20 element array are 0-19. If you take your original while loop attempt, and just move the x++ to the bottom, then it will use 0-19, which is correct.

    Follow the flow of each version in you head. Write down the value of x every time you reach the array[x] = x; part. Because you use x as an array index, it must be 0-19.

    If you want the values stored by the array to be 1-20, that is ok, but you need either a different variable for the index, or you need to add 1 to the index: array[x] = x+1; The key is that the index must go from 0-19, and you can do whatever you want to get the proper value.

  4. #19
    Registered User
    Join Date
    Nov 2005
    Posts
    37
    ok..thanks...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about arrays
    By TomButcher in forum C++ Programming
    Replies: 3
    Last Post: 09-02-2005, 09:27 AM
  2. A question concerning character arrays
    By ellipses in forum C Programming
    Replies: 3
    Last Post: 03-08-2005, 08:24 PM
  3. basic question to Arrays
    By doneirik in forum C++ Programming
    Replies: 1
    Last Post: 01-25-2005, 02:57 AM
  4. Question about char arrays
    By PJYelton in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2003, 12:44 AM
  5. question on multiplying 2D arrays
    By 3kgt in forum C++ Programming
    Replies: 4
    Last Post: 04-23-2003, 08:26 PM