Programming Note--I/O In Non-Standard Modula-2

Several references were made in Chapter two to the classical or pre-standard versions of Modula-2. In general, but with many variations, the entire contents of the standard modules SWholeIO and STextIO were found in the classical module InOut, and contents of SRealIO were found in the classical module RealInOut. Section 6.3.1 and Appendix 7 can be consulted for further details. The program here is a little illustration in classical Modula-2. As can readily be seen, there is not much difference between it and an ISO program.

MODULE ALittleMath;

 (* This program will ask for two numbers and multiply them.  *)

FROM InOut IMPORT
  WriteString, WriteLn, Read;
FROM RealInOut IMPORT
  ReadReal, WriteReal;

VAR
   userInput1, userInput2, ans : REAL;

BEGIN
  (* fetch input *)
  WriteString ("Give me a number, please. ");
  ReadReal (userInput1);
  WriteLn;
  WriteString ("And a second one, if you would. ");
  ReadReal (userInput2);
  WriteLn;
  (* do calculation *)
  ans := userInput1 * userInput2; 
  (* output *)
  WriteString ("The answer to your "); 
  WriteString ("multiplication problem is ====> ");
  WriteReal (ans, 15, 3);

END ALittleMath.

Contents