Jump to content

Soloway's recurring rainfall: Difference between revisions

m
→‎{{header|Raku}}: copy / pasto, add missing line, reformat slightly
m (→‎{{header|Raku}}: copy / pasto, add missing line, reformat slightly)
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.
 
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
# output their average. Stop reading when the
Line 585 ⟶ 583:
++$periods;
$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}}
<pre># Normal operation
10,333

edits

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