Jump to content


help with writing code with arrays

visual basic vb

  • Please log in to reply
4 replies to this topic

#1 soccerstar206



  • Joined: 19-August 13

Posted 24 August 2013 - 02:38

Given the following data:

Cartoon Character              Year of Creation

Bugs Bunny                                   1938

Homer Simpson                             1987

Fred Flintstone                              1960

Charlie Brown                                1950

Mickey Mouse                               1928


Write a program to:


Define two parallel arrays, one containing the Characters’ names, and one containing the year of creation.

Write code to traverse the arrays and output each name along with the year of its creation to the List Box, lstOutput.  While traversing the array, determine character is the oldest.


Then output to lstOutput, the sentence:

    "The oldest character in this group is ____________________. "

The blank should contain the name of the oldest character.         

#2 Lord Method Man

Lord Method Man


  • Tech Issues Solved: 1
  • Joined: 18-September 12

Posted 24 August 2013 - 02:49

Set a variable to keep track of the oldest character, initialize it to 99999 or something.


Inside the loop, if the year of creation for that character is less than the oldestCharacter, update oldestCharacter to that character's year of creation and save the character's name to a separate variable, output it at the end.

#3 GreenMartian


    Neowinian Senior

  • Joined: 28-August 04
  • Location: adelaide, au

Posted 24 August 2013 - 03:05

Here's a pseudo-code of how it might be done.
# Define 2 Arrays
Names are [bugs, homer, fred]
Years are [1938, 1987, 1960]

OldestName is Unknown
OldestYear is 99999

# Traverse the array while printing & determining oldest characters
With index from FirstIndex(Names) to LastIndex(Names)

    AddToList(Names[index], Years[index])

    If Years[index] less than OldestYear
        OldestYear is Years[index]
        OldestName is Names[index]

# Print final message
AddToList("The oldest character is", OldestName)
Now it's up to you to implement it in any language you like.

#4 +Heartripper



  • Tech Issues Solved: 2
  • Joined: 10-December 09
  • Location: Italy
  • OS: Windows 8.1 / OSX 10.10
  • Phone: Nokia Lumia 925

Posted 23 October 2013 - 07:28

It really looks like someone doesn't want to do his homework...

#5 +Majesticmerc


    Resident Idealist

  • Tech Issues Solved: 9
  • Joined: 24-August 05
  • Location: United Kingdom
  • OS: Arch Linux / Win 7
  • Phone: HTC One X

Posted 23 October 2013 - 11:58

If you have two coloumn data , better you use with other datastructure like hashtable. In hashtable you can input values like key and value and easy to retrieve . following link shows the hashtable implementation in c# http://csharp.net-in...p-hashtable.htm c# hashtable , hope this will help you.

Very true, but the way that the question is written, I suspect that this is homework on arrays. In the real world as you correctly say, an associative container would be better :)

P.S. Welcome to Neowin!

P.P.S. Please don't resurrect two month old topics ;)