• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

help with writing code with arrays


soccerstar206    1

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.         

Share this post

Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0
Lord Method Man    1,612

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.

Share this post

Link to post
Share on other sites
  • 0
GreenMartian    90

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.
  • Like 1

Share this post

Link to post
Share on other sites
  • 0
+Heartripper    184

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

  • Like 1

Share this post

Link to post
Share on other sites
  • 0
+Majesticmerc    872

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-informations.com/collection/csharp-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 ;)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.