Re: Tutorial of sorts

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

On Thu, 22 Oct 1998 00:52:29 -0700, Hawke <mdeland at NWINFO.NET> wrote:

>lithex wrote:
>> Here's my attempt at (Irv's) first problem:
>> --This is a version of PAY.ex
>> temp=value(cmd[4]) hours=temp[2]
>> temp=value(cmd[5]) payrate=temp[2]
>I hope I'm not intruding upon Irv's space when I say this,
>and I also hope that I'm not viewed as being nit picky,
>but I felt this was important to mention as it *is*
>a learning situation...
...
>I would think that right about now would be the perfect
>time to get into the habit of actually checking for
>that situation, and if that situation is found, you can
>either exit gracefully from the program (which gives you
>the opportunity to save potentially precious data) or
>you can reprompt the user for a more appropriate value.
>
>Yes, I understand that the parameters for the "tutorial"
>didn't really discuss this issue, but, once again, I
>feel it's never too early to develop this habit...

Indeed, that is the next step in this tutorial - we are
trying to write something that will actually be _useful_,
so things like parameter checking are important.

>you see this situation *actually coded* for (nearly) every
>routine that uses: fn=open("blah","w") if fn=-1 then...
>that gets posted to the listserv, so why should value()
>be any different, eh? :)

The problem? We don't want to write three-line input validation
routines for every input - gets boring, takes up space, and
increases the opportunity for misteaks to crepe in.

So we have assignment 1.1
Write a *validate* function, to take input, return a number
within a specified range, or print an error message and
abort.
Hint: see functions, abort() in the docs.
Suggested syntax:
hours = validate(cmd[4],{1,80},"Hours")
payrate = validate(cmd[5],{5.50,35.00},"Payrate")

Suggested output:
 * ERROR in Hours: should be between 1 and 80 *

Regards,

Irv

>As for the rest of the code, kudos indeed.
>IMO, well written, nice variable names, easily read...
>
>> Name    Hours worked       Gross pay     Tax       Net pay
>> Jose    40                 480.00        120.00    360.00
>I am wondering about the header that was supposed to
>go above the numeric output... ;)
>but i'll leave that one up to Irv :)

We might have to deduct a couple of points for overlooking
the header ;)

Irv

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

Search



Quick Links

User menu

Not signed in.

Misc Menu