Jump to content

Soloway's recurring rainfall: Difference between revisions

→‎{{header|ALGOL 68}}: Allow for negative rainfall
No edit summary
(→‎{{header|ALGOL 68}}: Allow for negative rainfall)
Line 76:
<syntaxhighlight lang="algol68">
BEGIN # read a sequence of integers, terminated by 99999 and outpout their average #
INT end value = 99999;
INT sum := 0;
INT count := 0;
BOOL invalid value := FALSE;
on value error( stand in, ( REF FILE f )BOOL: invalid value := TRUE );
WHILE
INT n := 0;
WHILE
STRING s;
print( ( "Enter rainfall (integer) or ", whole( end value, 0 ), " to quit: " ) );
read( ( sn, newline ) );
BOOL valid := UPB s >= LWB s; # invalid if the string is empty #value
FOR s pos FROM LWB s TO UPB s WHILE valid DO
IF valid := s[ s pos ] >= "0" AND s[ s pos ] <= "9"
THEN
n *:= 10 +:= ( ABS s[ s pos ] - ABS "0" )
FI
OD;
NOT valid
DO
print( ( "Invalid input, please enter an integer", newline ) );
invalid value := THENFALSE
OD;
n /= end value
3,043

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.