Soloway's recurring rainfall: Difference between revisions

m
allow negative integers
m (→‎{{header|Phix}}: use the wp formula)
m (allow negative integers)
Line 509:
 
=={{header|Julia}}==
Written for simplicity of reading rather than brevity. Changed from the originals to allow negative input, though I note that
allowing negative integer input and disallowing floating point seems strange given most "real-life" negative rainfall daily numbers are less than 1 inch.
<syntaxhighlight lang="julia">"""
Two annotated example outputs
Line 516 ⟶ 517:
the sentinel was the first and only input.
"""
function rainfall_problem(sentinel = 999999, allownegative = true)
total, entries = 0, 0
while true
print("Enter rainfall as $(allownegative ? "" : "nonnegative ") integer ($sentinel to exit): ")
n = tryparse(Int, readline())
if n == sentinel
break
elseif n == nothing || !allownegative && n < 0
println("Error: bad input. Try again\n")
else
4,108

edits