LearnStanmorephysics

Grade 10 · Delphi Foundations

DIV and MOD

Grade 10 · Data & calculations · Lesson and coding task · about 12 minutes

Open this task in the Delphi workspace →

Delphi has two kinds of division:

OperatorWorks onGivesExample
/any numbersReal answer7 / 2 = 3.5
DIVIntegers onlywhole part7 div 2 = 3
MODIntegers onlyremainder7 mod 2 = 1

DIV and MOD are a power couple. "How many full minutes in 245 seconds, and what is left over?"

iMinutes := 245 div 60;   // 4
iSeconds := 245 mod 60;   // 5

The same idea splits money into notes and coins, learners into full buses and stragglers, and digits off a number — DIV/MOD questions appear in every NSC paper.

Exam tip. If you catch yourself writing Trunc(iA / iB), you almost certainly wanted iA div iB. And remember DIV/MOD refuse to work on Real values.

What you will do

Hints
  1. There are 60 seconds in a minute, so DIV 60 and MOD 60.
  2. Build the caption with IntToStr: IntToStr(iMinutes) + ' min ' + IntToStr(iSeconds) + ' sec'
Model solution
procedure TfrmTime.btnConvertClick(Sender: TObject);
var
  iTotal, iMinutes, iSeconds : Integer;
begin
  iTotal := StrToInt(edtSeconds.Text);
  iMinutes := iTotal div 60;
  iSeconds := iTotal mod 60;
  lblAnswer.Caption := IntToStr(iMinutes) + ' min ' + IntToStr(iSeconds) + ' sec';
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.