LearnStanmorephysics

Grade 10 · Delphi Foundations

Input, output & VAT

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

Open this task in the Delphi workspace →

Users type into edit boxes (TEdit). Whatever they type is text, so edtPrice.Text is a String — even if they typed 100. To calculate with it you must convert:

rPrice := StrToFloat(edtPrice.Text);   // text -> Real
iAge   := StrToInt(edtAge.Text);       // text -> Integer

And to display an answer you convert back. For money we want exactly two decimals, so we use FloatToStrF:

lblTotal.Caption := 'Total: R ' + FloatToStrF(rTotal, ffFixed, 10, 2);

ffFixed, 10, 2 means: fixed notation, up to 10 significant digits, 2 decimals. So 115 becomes 115.00 — proper till-slip money.

Your task: a VAT calculator

South Africa charges 15% VAT. Given a price excluding VAT:

rVAT   := rPrice * 0.15;
rTotal := rPrice + rVAT;      // or rPrice * 1.15
Note. On a real SA Windows machine FloatToStrF(…, ffCurrency, …) shows the Rand symbol automatically, using your Regional Settings (often with a decimal comma: R 115,00). In exams you will usually build the R yourself as we do here.

What you will do

Hints
  1. rPrice := StrToFloat(edtPrice.Text);
  2. VAT is rPrice * 0.15. The total is the price plus the VAT.
  3. FloatToStrF(rTotal, ffFixed, 10, 2) gives '115.00' — put 'Total: R ' in front of it.
Model solution
procedure TfrmVAT.btnCalculateClick(Sender: TObject);
var
  rPrice, rVAT, rTotal : Real;
begin
  rPrice := StrToFloat(edtPrice.Text);
  rVAT := rPrice * 0.15;
  rTotal := rPrice + rVAT;
  lblTotal.Caption := 'Total: R ' + FloatToStrF(rTotal, ffFixed, 10, 2);
  memOutput.Lines.Add('VAT: R ' + FloatToStrF(rVAT, ffFixed, 10, 2));
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.