Back to Challenge Set 18

Code Challenge: Lost and Found

Difficulty  

divider

The Brief

What they asked for
The front office keeps a list of everything handed in and
where it is being kept. Students come and ask all day. Let
someone type what they lost and tell them where it is, or
that nobody has handed one in.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • Two arrays lined up by position: what was handed in, and where it is.
  • Search for the position, not the place. Once you know the index, the place is at the same index in the other array.
  • Something that was never handed in is a normal answer here, not an error. Activity 2.9's -1 is how the method says so.

Where to Start

Only one-star challenges have this section. If you already know how to begin, skip it — and when you move up to two stars, working out the order yourself is part of the job.

  1. Make the two arrays and decide on five items and five places.
  2. Write a method that takes the item and returns its index, or -1, the way Activity 2.9's SearchHouse did.
  3. Ask the student what they lost with Console.ReadLine, and call the method.
  4. Use an if on the returned index to print the place, or the not-found message.

Sample Output

Sample Output
What did you lose? hoodie [Enter]
A hoodie was handed in at the library.
What did you lose? phone [Enter]
No phone has been handed in yet.

Two separate runs: one item that was handed in, one that was not. Typed input is case-sensitive: Hoodie is not hoodie.


Submit

Your requirements list and your program file, named cc-lost-and-found.

Commence Challenge