CS137 Laboratory assignment #1

Your assignment is to type in the program below (found on pp. 38-39 of your text) and run it. When the program runs correctly, save your program to diskette, then print your program and also print the output it produces.

The program is listed below:

{CS137 Lab#1 }
PROGRAM Example;
USES
 Crt;
CONST 
 Skip = ' '; 
 LoopLimit = 10;
VAR 
 J, Number, Sum : integer;
 Average : real;
BEGIN ClrScr;
 Sum := 0;
 FOR J := 1 TO LoopLimit DO
   BEGIN writeln('Enter a number and press .');
     readln(Number);
     Sum := Sum + Number
   END;
 Average := Sum / LoopLimit;
 writeln;
 writeln(Skip:10, 'The average is', Average:8:2);
 writeln;
 writeln(Skip:1, 'The number of scores is',LoopLimit:3);
END. 

Hints:

  1. Save your program to disk once you've typed it in. Use the File menu item (ALT-F).
  2. You probably will make one or more typing errors--that's par for the course, even if you're careful. Never mind. When you try to run your program (Alt-R), it will probably not run because it will detect some syntax error. The cursor will be at that part of your program where the first encountered syntax error occurred. Correct it, and try running your program again. Keep doing this until it runs. Then save your program to diskette again.
  3. To see your output, select the DEBUG menu
  4. To print your program, use the File menu and scroll down to print.
  5. One way to print your output is to hold down the shift key and depress the Print Screen key (top right of the keyboard).