Back to Challenge Set 14

Code Challenge: Roster Print

Difficulty  

divider

The Brief

What they asked for
Print my team roster as a numbered list, one player per
line, with how many players there are at the top. The team
changes during the season, so it has to work for any number
of players.

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


Notes

  • Put the players in an array in your code: Avery, Blake, Casey, Dakota, Emery.
  • “Any number of players” means one loop, not one line per player. The standard traversal from Activity 1.25 does exactly this.
  • The list is numbered from 1, the way people read it. The array counts from 0.
  • Add a sixth player and run it again. The count and the list should both grow with no other change.

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 players.
  2. Print the heading with the number of players, from .Length.
  3. Write a for loop over every index of the array.
  4. Inside it, print the player's number and name. Work out the number from the index.
  5. Add a sixth name and run it again.

Sample Output

Sample Output
Team roster (5 players):
1. Avery
2. Blake
3. Casey
4. Dakota
5. Emery

Verified in a real run, and again with a sixth player added.


Submit

Your requirements list and your program file, named cc-roster-print.

Commence Challenge