Jump to content

Soloway's recurring rainfall: Difference between revisions

J draft
(→‎{{header|Wren}}: Added sample input/output)
(J draft)
Line 307:
end program recurringrainfall
</syntaxhighlight>
 
=={{header|J}}==
The specification for this task seems inadequate. So, we'll copy some features from other implementations of this task.
 
Specifically, we'll issue a prompt for every number requested, and reject lines which contain something that is not a number.
 
However, since we're supposedly collecting information about rainfall, and rainfall is not necessarily an integer, we'll allow arbitrary numbers here and trust the judgement of the person entering the numbers.
 
Implementation: <syntaxhighlight lang=J>require'general/misc/prompt'
 
task=: {{
list=. ''
whilst. -.99999 e. y do.
y=. _.".prompt'Enter rainfall int, 99999 to quit: '
if. y-:y do. list=. list,y
else. echo 'invalid input, reenter'
end.
end.
(+/%#)list-.99999
}}</syntaxhighlight>
 
Example use:<syntaxhighlight lang=J> task''
Enter rainfall int, 99999 to quit: 2
Enter rainfall int, 99999 to quit: 3
Enter rainfall int, 99999 to quit: 5
Enter rainfall int, 99999 to quit: 7
Enter rainfall int, 99999 to quit: 11
Enter rainfall int, 99999 to quit: 99999
5.6</syntaxhighlight>
 
=={{header|Java}}==
6,962

edits

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