Grade 10 · Decisions · Lesson and coding task · about 14 minutes
Open this task in the Delphi workspace →
Conditions combine with AND, OR and NOT. In Delphi each comparison must be in its own brackets:
if (rAvg >= 75) and (iMaths >= 70) then // both must be true
if (sDay = 'Sat') or (sDay = 'Sun') then // at least one true
Leave the brackets out and Delphi refuses to compile — a classic exam-day panic that you are now vaccinated against.
For several possibilities in a row, chain IFs into a ladder. Order matters: test the strictest condition first.
if (rAvg >= 75) and (iMaths >= 70) then
lblResult.Caption := 'Bursary awarded!'
else
if rAvg >= 75 then
lblResult.Caption := 'So close - improve your Maths mark'
else
lblResult.Caption := 'Keep working at it';
Your task: bursary checker
A university bursary requires an average of at least 75% AND a Maths mark of at least 70%. Implement exactly the ladder above.
What you will do
- Read the average and the Maths mark from the two edit boxes
- Average >= 75 AND Maths >= 70: Bursary awarded!
- Average >= 75 but Maths below 70: So close - improve your Maths mark
- Otherwise: Keep working at it
Hints
- Each comparison gets its own brackets: (rAvg >= 75) and (iMaths >= 70)
- The second rung of the ladder only needs to test the average — the Maths mark already failed if we got there.
- No semicolons before the elses!
Model solution
procedure TfrmBursary.btnApplyClick(Sender: TObject);
var
rAvg : Real;
iMaths : Integer;
begin
rAvg := StrToFloat(edtAvg.Text);
iMaths := StrToInt(edtMaths.Text);
if (rAvg >= 75) and (iMaths >= 70) then
lblResult.Caption := 'Bursary awarded!'
else
if rAvg >= 75 then
lblResult.Caption := 'So close - improve your Maths mark'
else
lblResult.Caption := 'Keep working at it';
end;