Pascal – Iteration and Input

email me

Tested in Free Pascal.

Code

PROGRAM LoopAndInput (input, output);

CONST
    LoopLimit = 5;

VAR
    Index, Number, Sum : integer;
    Average : real;

BEGIN
    Sum := 0;
    FOR Index := 1 TO LoopLimit DO
        BEGIN
            writeln (#13#10'Enter number ', Index, ' of ', LoopLimit);
            readln (Number);
            Sum := Sum + Number
        END;
    Average := Sum / LoopLimit;
    writeln;
    writeln ('Average:', Average:5:0);
    writeln;
    readln;
  END.

 

Output

 


Notes

Syntax Highlighter

Online Compiler

Free Pascal compiler