(phixonline)-->
with javascript_semantics
include pGUI.e
Ihandle lab, tab, res, dlg
constant fmt = """
a = %d
b = %d
a + b = %d
a - b = %d
a * b = %d
a / b = %g (does not truncate)
remainder(a,b) = %d (same sign as first operand)
power(a,b) = %g
"""
function valuechanged_cb(Ihandle tab)
string s = IupGetAttribute(tab,"VALUE")
sequence r = scanf(s,"%d %d")
if length(r)=1 then
integer {a,b} = r[1]
s = sprintf(fmt, {a, b, a+b, a-b, a*b, a/b, remainder(a,b), power(a,b)})
IupSetStrAttribute(res,"TITLE",s)
IupRefresh(res)
end if
return IUP_DEFAULT
end function
procedure main()
IupOpen()
lab = IupLabel("Enter two numbers")
tab = IupText("VALUECHANGED_CB", Icallback("valuechanged_cb"),"EXPAND=HORIZONTAL")
res = IupLabel("(separated by a space)\n\n\n\n\n\n\n","EXPAND=BOTH")
dlg = IupDialog(IupVbox({IupHbox({lab,tab},"GAP=10,NORMALIZESIZE=VERTICAL"),
IupHbox({res})},"MARGIN=5x5"),
`SIZE=188x112,TITLE="Arithmetic/Integer"`)
IupShow(dlg)
if platform()!=JS then
IupMainLoop()
IupClose()
end if
end procedure
main()