Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

storing values into an array

 
Mike Pirrone
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, we are all the way up to inheritance at this point in my class but I am still having problems with storing values into an array. are there any websites that could offer me some help on the subject? I can declare an array perfectly but what I am trying to figure out, is how to store values that a user enters into an array and then print out the entire array of values that the user entered. thank you so much
-mike-
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two cents on arrays...
First penny: array + loop = beauty and power
The beauty of using arrays is realized with the power of looping. We don't have to code repititiously for each component in the array - we use the repitions of a loop.
So, to fill an array with data and then display the components in the array, you could:
1. declare and intialize your array with some length
2. use a for loop to prompt the user for data and add that data to the array until the end of the array is reached
3. use another for loop to display the entire contents of the array
These for loops could look something like:

Second penny: If you were to do a search on this forum (the search page link is at the top right of this page), I'd bet you'd find lots of useful information on arrays (and many other topics).
Good Luck.
[ April 02, 2002: Message edited by: Dirk Schreckmann ]
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you ever get confused about an array, just draw a picture. You'll find that arrays are very easy once you can visualize them. Take a look at this example:

In this picture, I have the array indices drawn over the top of the array. Now, if I want to get the value 101 out of the array, I'd access intArray[1]. If I wanted to get 103, I'd access intArray[3].
Drawing pictures always makes things easier for me. Hopefully, this will help you, too.
Corey
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic