How to resolve the algorithm Soloway's recurring rainfall step by step in the ALGOL 68 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Soloway's recurring rainfall step by step in the ALGOL 68 programming language

Table of Contents

Problem Statement

Soloway's Recurring Rainfall is commonly used to assess general programming knowledge by requiring basic program structure, input/output, and program exit procedure. The problem: Write a program that will read in integers and output their average. Stop reading when the value 99999 is input. For languages that aren't traditionally interactive, the program can read in values as makes sense and stopping once 99999 is encountered. The classic rainfall problem comes from identifying success of Computer Science programs with their students, so the original problem statement is written above -- though it may not strictly apply to a given language in the modern era. Implementation Details: The purpose of this problem, as originally proposed in the 1980's through its continued use today, is to just show fundamentals of CS: iteration, branching, program structure, termination, management of data types, input/output (where applicable), etc with things like input validation or management of numerical limits being more "advanced". It isn't meant to literally be a rainfall calculator so implementations should strive to implement the solution clearly and simply. References:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Soloway's recurring rainfall step by step in the ALGOL 68 programming language

Source code in the algol programming language

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
            print( ( "Enter rainfall (integer) or ", whole( end value, 0 ), " to quit: " ) );
            read( ( n, newline ) );
            invalid value
        DO
            print( ( "Invalid input, please enter an integer", newline ) );
            invalid value := FALSE
        OD;
        n /= end value
    DO
        sum   +:= n;
        count +:= 1;
        print( ( "New average: ", fixed( sum / count, -12, 4 ), newline ) )
    OD
END

  

You may also check:How to resolve the algorithm Ludic numbers step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Heronian triangles step by step in the C programming language
You may also check:How to resolve the algorithm Combinations with repetitions step by step in the Racket programming language
You may also check:How to resolve the algorithm Filter step by step in the XQuery programming language
You may also check:How to resolve the algorithm Menu step by step in the PowerShell programming language