Back to Challenge Set 2

Code Challenge: Score Average

Difficulty  

divider

The Brief

What they asked for
I want to know my average across three assignments so I can
see where I stand before grades close. Just the three
scores in, the average out, one decimal place.

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


Notes

  • This one has a trap in it, and you will hit it if you skip a step. Run your program with 88, 92, and 79 before you do anything else.
  • If your average prints as 86.0, you found the trap — and it will look fine unless you check it by hand. Work out what happened before you fix it. The explanation is worth more than the fix.
  • One decimal place is required. The correct answer for those three scores is 86.3.

Sample Output

Sample Output
Score 1: 88 [Enter]
Score 2: 92 [Enter]
Score 3: 79 [Enter]
Average: 86.3

86.0 is what :F1 shows you when the division underneath it already truncated to a whole number. The format specifier only controls how a number is printed — it cannot recover a decimal that arithmetic already threw away. Activity 1.6 has the fix.


Submit

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

Commence Challenge