Module: Subroutines: procedures and functions - 1


Problem

2/12

Parameters and Arguments

Theory Click to read/hide

Now let's imagine that we need to display different messages in response to a user's error, depending on what kind of mistake he made.
In this case, you can write your own procedure for each error:  

procedure printErrorZero();
begin
    writeln('Error. Division by zero!');
end;

procedure printErrorInput();
begin
    writeln('Error in input!');
end;

What if there are many more possible errors? This solution will not suit us!
We need to learn how to control the procedure by telling it what error message to display.
To do this, we need parameters that we will write in parentheses after the procedure name
procedure printError(s: string);
begin
    writeln(s);
end;
In this procedure, s is a parameter - a special variable that allows you to control the procedure.
The parameter is a variable that determines how the subroutine works. Parameter names are listed separated by semicolons in the subprogram header. After the parameter, a colon is followed by its type.

Now, when calling the procedure, you need to indicate in brackets the actual value that will be assigned to the parameter (variable s) inside our procedure
printError('Error! Division by zero!');
This value is called an argument.
The argument is the parameter value that is passed to the subroutine when it is called.
An argument can be not only a constant value, but also a variable or an arithmetic expression.

Problem

In the program, it is necessary to add procedure calls in such a way that when entering the value 0, the error "Error: division by zero!", is displayed on the screen, otherwise an error is displayed "Error in input!".
Your job is to make the correct call to the procedure.