Re: Tutorial 1.2
- Posted by lithex <lithex at INTERGATE.BC.CA> Oct 24, 1998
- 518 views
Hi I tried to incorporate Hawke's abhorance of abort()into my attempt at a "validate" function. Unlike Ad, I've decided that I won't allow direct user input into the program - I'm assuming that pay.ex gets called by a dos batch file that passes it parameters in the command line. What I've done is make the output into nothing if the data isn't right rather than either seeking correction or aborting execution. My guess was that the data would then be passed to some book keeping function next. Imagine my surprise and delight when I find the next routine is the cheque writer, without even letting the book-keeper know. Yeah! That's my kind of accounting!( -- Start of Euphoria Code --This is a version 1.1 of PAY.ex by Martin Hunt global constant ISVALID=1 global constant ISNOTVALID=0 global atom Validation Validation=ISVALID sequence cmd, name, titleline atom taxrate, hours, payrate, takehome, gross, tax titleline={"Name","Hours worked","Gross pay","Tax","Net pay"} include get.e function validate(sequence Thisthinghere, sequence Range, sequence Errprompt) sequence valresult valresult=value(Thisthinghere) if valresult[1] != GET_SUCCESS then Validation=ISNOTVALID printf(1, "*ERROR in %s: Not a number*\n",{Errprompt}) else if (valresult[2] < Range[1]) or (valresult[2] > Range[2]) then Validation=ISNOTVALID printf(1, "*ERROR in %s: should be between %3.1f and %3.1f*\n", {Errprompt, Range[1], Range[2]}) end if end if return (valresult[2]) end function cmd=command_line() if length(cmd) !=5 then printf(1, "Data entry error at command line",{}) abort(0) end if name=cmd[3] hours=validate(cmd[4],{1,80},"Hours") payrate=validate(cmd[5],{5.50,35.00},"Payrate") taxrate=0.25 if Validation = ISVALID then gross=hours*payrate tax=gross*taxrate takehome=gross-tax printf(1, "%9s %12s %12s %12s %12s\n", titleline) printf(1, "%9s %12d %12.2f %12.2f %12.2f\n", {name, hours, gross, tax, takehome}) else gross=0 tax=0 takehome=0 printf(1, "Data error: Nothing done",{}) end if -- End of Euphoria Code Bye Martin