16 lines
621 B
Text
16 lines
621 B
Text
fun main ← int by List args
|
|
text input ← when(args.length æ 1, args[0], ask(text, "Enter n integers separated by a space: "))
|
|
int sum, count
|
|
for each text word in input.split(" ")
|
|
word ← word.trim()
|
|
if word.isEmpty() do continue end # ignore empty words
|
|
int nr ← int!word # this can raise an exception
|
|
if abs(nr) > 1000 do error(0, "Integers must be in the interval [-1000, 1000]") end
|
|
sum += nr
|
|
++count
|
|
end
|
|
if count < 2 do error(1, "At least two integers must be provided") end
|
|
writeLine("The sum of " + count + " integers is: " + sum)
|
|
return 0
|
|
end
|
|
exit main(Runtime.args)
|