program ex10;
var a, b, c, sum: real;
f: char;
begin
writeln ('Enter a real number');
readln (a);
writeln ('Enter another real number');
readln (b);
writeln ('Enter one more real number');
readln (c);
sum:=a + b + c;
writeln ('Do you want the output r)ounded or t)runcated?')
readln (f);
if (f='r') then sum:= round(sum)
else sum:=trunc(sum);
writeln ('Sum is: ', sum: 8);
readln;
end.
The user is asked to enter 'r' to round the result or 't' to truncate it. Rounding a real number follows the standard rules, returning the nearest integer to the result, so 3.5 becomes 4, 3.49 becomes 3. The Truncate function simply cuts off the fractional part do 3.5 becomes 3. With no decimal places to show the format descriptor is simply 8, the width of the output. Both trunc() and round() perform a typecast operation as a real number is turned into an integer.