Pascal: Income Tax 1

program ex13;

const basic_tax_rate=23;
         
var income, net_income: real;
begin
  writeln ('Enter a value for income');
  readln (income);
  net_income:= income - (income * basic_tax_rate / 100);
  writeln ('Income after tax is: £', net_income: 8:2);
  readln;
end.

Notice the output of the '£' before the number. To place the £ symbol immediately before the number (as in '£450.45', as opposed to '£      450.45') it would be necessary to find the number of digits in the number and to set the width part of the format descriptor accordingly. Something like: if (net_income > 100) and (net_income < 1000) then fdwidth := 5, etc.). Alternatively, we could convert the number to a string (characters), add the '£' and also add blank spaces before the '£' to ensure a constant width.

Back to questions