Lesson 81 +10 XP

Project: Grade Calculator

Project 2: Grade Calculator

Read scores, compute an average, and show a letter.

Outline

  1. Ask how many scores.
  2. Loop and sum them.
  3. Compute average.
  4. Map to a letter:
if (avg >= 90)      printf("A");
else if (avg >= 80) printf("B");
else if (avg >= 70) printf("C");
else                printf("F");

Pseudocode

score total = 0
for i in 1..count:
     total += input
avg = total / count
pick letter from avg

Extend

  • Handle 0 scores.
  • Also print the average.
  • Support decimals with %f.

TL;DR

  • Accumulate in a loop.
  • Divide to average.
  • Chain else-if buckets for the letter.