Based on programming/2007-April/006067 discussion:
Roughly, equivalents of
puts and gets in C are
smoutput and prompt in J.
Thus we have:
«arith_prompt.ijs»=
require 'misc' NB. prompt
main=: 3 : 0
while.1 do.
'x y'=. ":&.>3+2?@$10
'op'=. ({~ ?@#)'+-*'
if. 0=#z=. 0".prompt (exp=. x,op,y),' = '
do.'Bye!'break.end.
smoutput (10#' '),(z=".exp)>@{'Wrong';'Correct!'
end.
)
The above snippet can pasted into a new J window and run, or into jconsole, or loaded like below.
load '~user/arith_prompt.ijs'
main''
6-8 = -2
Correct!
12*8 = 96
Correct!
3*12 = 1
Wrong
3+10 = 13
Correct!
11*4 = 44
Correct!
10-5 =
Bye!
Contributed by OlegKobchenko
