LearnStanmorephysics

Grade 10 · Delphi Foundations

The CASE statement

Grade 10 · Decisions · Lesson and coding task · about 14 minutes

Open this task in the Delphi workspace →

When one Integer (or Char) value chooses between many options, a CASE statement beats a long IF ladder:

case iMark div 10 of
  8..10 : sLevel := 'Level 7';
  7     : sLevel := 'Level 6';
  6     : sLevel := 'Level 5';
  else    sLevel := 'Level 1';
end;

Note the trick: iMark div 10 turns 0–100 into 0–10, so each band becomes one label. Ranges like 8..10 and lists like 1, 3, 5 are allowed. CASE only works on ordinal types (Integer, Char) — never on Strings.

Your task: NSC achievement levels

Report marks use these levels — build the full table with one CASE:

MarkLevel
80–100Level 7 (Outstanding)
70–79Level 6 (Meritorious)
60–69Level 5 (Substantial)
50–59Level 4 (Adequate)
40–49Level 3 (Moderate)
30–39Level 2 (Elementary)
0–29Level 1 (Not achieved)

What you will do

Hints
  1. 84 div 10 = 8, so 8..10 covers 80–100 (and the mark 100 itself gives 10).
  2. Each line is value : statement; — for example 7 : sLevel := 'Level 6 (Meritorious)';
  3. Marks 0–29 give 0, 1 or 2 — let the else catch them.
Model solution
procedure TfrmLevels.btnLevelClick(Sender: TObject);
var
  iMark : Integer;
  sLevel : String;
begin
  iMark := StrToInt(edtMark.Text);
  case iMark div 10 of
    8..10 : sLevel := 'Level 7 (Outstanding)';
    7     : sLevel := 'Level 6 (Meritorious)';
    6     : sLevel := 'Level 5 (Substantial)';
    5     : sLevel := 'Level 4 (Adequate)';
    4     : sLevel := 'Level 3 (Moderate)';
    3     : sLevel := 'Level 2 (Elementary)';
    else    sLevel := 'Level 1 (Not achieved)';
  end;
  lblLevel.Caption := sLevel;
end;

About this material

This platform provides original CAPS-aligned practice material and study tools. Content is machine-verified and has not been reviewed by subject specialists. It is not affiliated with or endorsed by the Department of Basic Education. Learners should also use official past papers and consult their teachers where uncertain.