Learn Pascal Programming with Mc Kenzie

CHARACTERS and STRINGS

Character variables can represent only a single character while String variables can represent one or more characters. READ and READLN statements also allow users to input character and string data while the program is running. The statement : read(name); allows the user to input a string value where NAME has been declared as a string.     Var name : string;

 

Program 6B

This program accepts one or more character(s). Standard Pascal does not support the STRING type but Turbo Pascal and UCSD Pascal along with more updated versions do.

Remember READLN and READ operate similarly and either can be used to get user input values.

program Greeting(input,output);
Var
    name : string;
begin
   writeln('Please type your first name : ');
   read(name);
   writeln('Greetings ',name);
   readln
   end.

Program 6B is made up of three sections:

   1. The Program Heading starts with the word PROGRAM followed by the name of the program. The name of this program is Greeting. The heading ends with the first semi-colon after (input, output) which tells us that the program expects user input before it produces output on screen.

   2. The declaration section begins with Var followed by a string variable name then a colon before the word STRING. The last character on the line is the semi-colon.

   3. The body of the progarm starts with the word begin and terminates with the word end.

Test Yourself

Suppose a user with the first name CHERYL runs this program and enters her first name in block letters (upper-case). Write exactly what the output would be.

BSS Main | Previous Lesson | Next Lesson |

InfoDAM Web Technologies©MMX