Soloway's recurring rainfall: Difference between revisions

Content added Content deleted
m (→‎{{header|Raku}}: copy / pasto, add missing line, reformat slightly)
Line 567: Line 567:


I notice that units are specified for neither measurement; time nor rainfall accumulation. Time is assumed to always increment in units of one, rainfall in some non-negative integer. "Integer" gets a little leeway in this entry. Floating point numbers or Rational numbers that are exactly equal to an Integer are allowed, even if they are technically not integers.
I notice that units are specified for neither measurement; time nor rainfall accumulation. Time is assumed to always increment in units of one, rainfall in some non-negative integer. "Integer" gets a little leeway in this entry. Floating point numbers or Rational numbers that are exactly equal to an Integer are allowed, even if they are technically not integers.

On cursory observation this entry seems to needlessly duplicate the output line, but the second is there to accurately summarize the totals on program exit, even if no entries have been made, and to demonstrate that 999999 does '''not''' get added into the average.
<syntaxhighlight lang="raku" line># Write a program that will read in integers and
<syntaxhighlight lang="raku" line># Write a program that will read in integers and
# output their average. Stop reading when the
# output their average. Stop reading when the
Line 585: Line 583:
++$periods;
++$periods;
$accumulation += $rainfall;
$accumulation += $rainfall;
say-it;
printf "Average rainfall %.2f units over %d time periods.\n", $accumulation / $periods, $periods;
}
}

</syntaxhighlight>
say-it;

sub say-it { printf "Average rainfall %.2f units over %d time periods.\n", ($accumulation / $periods) || 0, $periods }</syntaxhighlight>
{{out}}
{{out}}
<pre># Normal operation
<pre># Normal operation