Unit 1.4 Reading with Nice Prompts

PROG

Reads two numbers and produces the sums.

PED

To learn how to make your program have nice prompts.

CONCEPTS

To retrieve a number with a prompt "ppp".

write('ppp ');
read(box_name);

SF

character string constant

'text'



Unit 1.4 Reading with Nice Prompts

Click here to view Unit 1.4 Pascal program.

When we run either of the two programs discussed before, the machine simply wait for a number to be typed at it. The user of the program has no idea what number the program wants. In fact the user might not realize that any number is wanted.

We would also like to label the answers so the user knows what each number that the program spits out is for.

This is real simple. To lable a number to be read, we simply put in our program:

write('ppp ');
read(box_name);

The space between the ppp and the quote will cause a nice separation between the text and the number that the user types in. When the user types in the number wanted, the carriage return that the user types, will separate the prompt and the user input from the next item input or output.

The form 'text ' is a character string constant. There is another variable type called "string" which contains character strings. It is called "string." A character string constant is to the string type what 123 is to an integer.