Soloway's recurring rainfall: Difference between revisions
Content added Content deleted
(Added Wren) |
(Added Algol 68) |
||
Line 62: | Line 62: | ||
end loop; |
end loop; |
||
end RecurringRainfall; |
end RecurringRainfall; |
||
</syntaxhighlight> |
|||
=={{header|ALGOL 68}}== |
|||
<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; |
|||
WHILE |
|||
INT n := 0; |
|||
WHILE |
|||
STRING s; |
|||
print( ( "Enter rainfall (integer) or ", whole( end value, 0 ), " to quit: " ) ); |
|||
read( ( s, newline ) ); |
|||
BOOL valid := UPB s >= LWB s; # invalid if the string is empty # |
|||
FOR s pos FROM LWB s TO UPB s WHILE valid DO |
|||
IF s[ s pos ] < "0" OR s[ s pos ] > "9" |
|||
THEN |
|||
valid := FALSE # invalid characters # |
|||
ELSE |
|||
n *:= 10 +:= ( ABS s[ s pos ] - ABS "0" ) |
|||
FI |
|||
OD; |
|||
NOT valid |
|||
DO |
|||
print( ( "Invalid input, please enter an integer", newline ) ) |
|||
OD; |
|||
n /= end value |
|||
DO |
|||
sum +:= n; |
|||
count +:= 1; |
|||
print( ( "New average: ", fixed( sum / count, -12, 4 ), newline ) ) |
|||
OD |
|||
END |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||