PROGRAM calculate_areas;

(*  This program is dedicated to Marsha, a student, who
    was of tremendous help during the debugging stage of
    the text and programs. Thanks Marsha!
*)

VAR in_char : CHAR;

PROCEDURE area_of_square;
VAR length,area : REAL;
BEGIN
  WRITE('Square   Enter length of side ');
  READLN(length);
  area := length * length;
  WRITELN('The area is ',area:12:4);
END;

PROCEDURE area_of_rectangle;
VAR width,height,area : REAL;
BEGIN
  WRITE('Rectangle   Enter width ');
  READLN(width);
  WRITE('Enter height ');
  READ(height);
  area := width * height;
  WRITELN('    The area is ',area:12:4);
END;

PROCEDURE area_of_triangle;
VAR base,height,area : REAL;
BEGIN
  WRITE('Triangle     Enter base ');
  READLN(base);
  WRITE('Enter height ');
  READ(height);
  area := 0.5 * base * height;
  WRITELN('    The area is ',area:12:3);
END;

PROCEDURE area_of_circle;
VAR radius,area : REAL;
BEGIN
  WRITE('Circle    Enter radius ');
  READLN(radius);
  area := 3.141592 * radius * radius;
  WRITELN('The area is ',area:12:3);
END;

BEGIN  (* main program *)
REPEAT
  WRITELN;
  WRITELN('You only need to input the first letter of the selection');
  WRITELN('Select shape; Square Rectangle Triangle Circle Quit');
  WRITE('Requested shape is ');
  REPEAT UNTIL keypressed;
  READ(kbd,in_char);
  CASE in_char OF
  'S' : area_of_square;
  's' : area_of_square;
  'R' : area_of_rectangle;
  'r' : area_of_rectangle;
  'T' : area_of_triangle;
  't' : area_of_triangle;
  'C' : area_of_circle;
  'c' : area_of_circle;
  'Q' : WRITELN('Quit');
  'q' : WRITELN('Quit');
  ELSE WRITELN(' undefined entry');
  END;
UNTIL (in_char = 'Q') OR (in_char = 'q');
END.  (* of main program *)