Experimenting with String Variables

This exercise assumes that you have the program Names2 loaded in the editor:

program Names2;
{$APPTYPE CONSOLE}
uses
  SysUtils;
const
  Q1 = 'What is your first name? ';
  Q2 = 'What is your last name? ';
  GREET_START = 'Hello, ';   
var
  Forename, Surname, Fullname : string;
begin
  write(Q1);
  readln(Forename);
  writeln(GREET_START, Forename);
  write(Q2);
  readln(Surname);
  Fullname := Forename + ' ' + Surname;
  writeln(GREET_START, Fullname);
  readln;
end.
Try the following:
  1. You could obtain the same result without using the variable Fullname by using the statement writeln(GREET_START, Forename, ' ', Surname);. Try inserting this statement and comment out the existing writeln(GREET_START, Fullname); statement. This will work, but the variable Fullname should be useful as you develop the program. Also, if you are too sparing with the use of variables, your programs can become difficult to read and understand.
  2. Adapt the program so that it will also handle the user's middle name.
  3. Write a program to evaluate '123' + '321'. Predict the outcome before running the program.
Programming - a skill for life!

The various types of constants and variables and how to use them