It's not complicated.
Code:
if (newresult > maxresult)
    maxresult = newresult