Back to Challenge Set 12

Code Challenge: Seat Finder

Difficulty  

divider

The Brief

What they asked for
I have one row of five seats and I can never remember who
sits where. Let me type a seat number and tell me who is in
it. Seat 1 is the one by the door.

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


Notes

  • Put the five names in an array in your code, in seat order: Avery, Blake, Casey, Dakota, Emery. You do not need to ask for them.
  • The person types a seat number from 1 to 5, because that is how people count seats. The array counts from 0. Those are both true at once, and connecting them is the challenge — Activity 1.23's cups did exactly this.
  • Test the two ends, seat 1 and seat 5. If either one shows the wrong name, the mistake is in how the seat number becomes an index.
  • A seat that does not exist, like 6, will crash the program. That is fine for now — Activity 1.24 is about stopping it.

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. Write the array of five names.
  2. Ask for the seat number and read it as an int.
  3. Print the seat number and the name in that seat. Work out which index seat 3 is before you write the line.
  4. Run it with 1, 3, and 5, and check each name against your array.

Sample Output

Sample Output
Which seat? (1-5) 3
Seat 3: Casey

Verified in a real run — seat 1 is Avery, seat 3 is Casey, and seat 5 is Emery.


Submit

Your requirements list and your program file, named cc-seat-finder.

Commence Challenge