Turbo Pascal Tutorial - Part II -
- Reading and Writing Information.
We will stick to use of the keyboard for reading information, and
the monitor for writing information right now.
read(a_number);
This command stops the program and waits for the user to input data
which will be placed in the variable a_number and does NOT produce
a movement to a new line.
readln(x);
This command does exactly as read, but produces a movement to a new
line.
write(x);
This command writes the contents of x to the screen without a
new line.
writeln(x);
This command does exactly as write, but produces a movement to a new
line.
- Sample Program
program tutorial2;
var
some_text: string;
begin
write('Type some text and press ENTER when done: ');
readln(some_text);
writeln('You just typed the following: ', some_text);
end.
Type in the program above and try it out!
- Assignment #1
Write a Pascal program that will accept two integers from the keyboard,
presenting the user with a prompt to enter a number for each integer.
Then print out statements which tell us what the two digits add up to,
subtract to, and multiply to. To be correct, you must act on the first
number and then the second number in your computations.
For example, 14 and 7 (in that order) would be treated as
14+7, 14-7, and 14*7.
PS. Call and save your program assign2
Example Monitor Screen (using 14 and 7):
Please enter the 1st number: 14
Please enter the 2nd number: 7
Adding 14 and 7 gives 21.
Subtracting 7 from 14 gives 7.
Multiplying 14 and 7 gives 98.