Back to Challenge Set 20

Code Challenge: New High Score

Difficulty  

divider

The Brief

What they asked for
The arcade's top-five board is already in order, best first.
When someone finishes a game I want their score slotted into
the right place, everyone below pushed down one, and the last
place falling off. Do not sort the whole board again.

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


Notes

  • The board is already sorted. Use that: a new score only has to find its place, not rearrange everything.
  • Names have to move with their scores, as in Activity 2.12, or the board will credit the wrong player.
  • Work from the bottom of the board up, moving each lower score down one place until you reach the spot where the new one belongs.
  • A score lower than the last place does not make the board. Say so.

Sample Output

Sample Output
1. Ada 980
2. Bo 870
3. Cy 750
4. Dee 620
5. Eli 510
Kai scores 800: place 3
Lu scores 400: not on the board
1. Ada 980
2. Bo 870
3. Kai 800
4. Cy 750
5. Dee 620

Kai's 800 lands in third; Cy and Dee move down and Eli drops off. Lu's 400 changes nothing.


Submit

Your requirements list and your program file, named cc-new-high-score.

Commence Challenge