Re: Tutorial of sorts

new topic     » goto parent     » topic index » view thread      » older message » newer message

>>assignment 1.1A perhaps?
>>Write a validate function, to take an input from the
>>user or the command line, and return a number within
>>a specified range, or print an error message and
>>allow the user the ability to retype the improper input,
>>without having to have the user retype *all* of the
>>other inputs (such as only one parameter on the command
>>line being improper... just fix that one parameter)
Irv wrote:
>OK, if you can do it in 10 lines or less. We're trying to
>keep this at the beginning programmer level.
I get your point  blink
Allright, here's my attempt. The function is 12 lines. You can deduct me =
2
points.

-- validate.e
-- a simple function to get data input from the user, and check for bound=
s

include get.e

function validate(sequence prompt, sequence bounds)
object result
    while 1 do
        puts(1, prompt & ' ')
        result =3D gets(0)
        result =3D value(result[1..length(result)-1])
        if result[1] =3D GET_SUCCESS then
            if result[2] >=3D bounds[1] and result[2] <=3D bounds[2] then=

                return result[2]
            end if
        end if
        printf(1, "\nError! Range =3D %.2f to %.2f\n", bounds)
    end while
end function

--test
? validate("Hours worked:", {1, 80})
-- end of Euphoria code

Ad

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu