Re: Tutorial of sorts

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

--On Wed, 21 Oct 1998 23:14:11 +0000, lithex <lithex at INTERGATE.BC.CA> wrote:

--Hi
--I like Irv's idea of programming problems as a way of teaching
--Euphoria.

--Here's my attempt at his first problem:
-------------------------------------------------------
-- * Comments added for those who are new to Euphoria *
-------------------------------------------------------
--Euphoria code starts:
--This is a version of PAY.ex

sequence cmd, name, temp
atom taxrate, hours, payrate, takehome, gross, tax

include get.e -- * file get.e allows you to use the value() function

cmd=command_line()

name=cmd[3] -- * command line input is parsed and can be indexed
-- * [1] will be the exe program, here "c:\euphoria\bin\ex.exe"
-- * [2] will be the ex program, here "pay"
-- * [3] will be "Jose"
-- * [4] will be 40
-- * [5] will be 12.00
-- * etc.

temp=value(cmd[4]) hours=temp[2]
temp=value(cmd[5]) payrate=temp[2]
-- * value returns a sequence of 2 numbers, i.e. {0,40}
-- * the first is a success/fail flag, the second is the value.
-- * if the first is not = GET_SUCCESS, then there was an error
-- * in the input, probably a non-numeric value.

taxrate=0.25

gross=hours*payrate
tax=gross*taxrate
takehome=gross-tax

printf(1, "%9s %12.2f %12.2f %12.2f %12.2f", {name, hours, gross, tax,
takehome})
--Euphoria code ends


-- Assignment 1;
-- Write a program that takes input at the command line as follows:
-- C:> ex PAY Jose 40 12.00
-- and returns:
-- Name         Hours worked       Gross pay     Tax       Net pay
-- Jose         40                 480.00        120.00    360.00
-- Hints:
-- See command_line and printf in your Euphoria docs.
-- For simplicity, tax is assumed to be fixed at 25% of gross.

-- Everyone is welcome to post solutions. Credit will be given for
-- clear, concise code, good comments, and use of Euphoria-specific
-- language features. Major points will be deducted for programs that
-- do not work. A lovely certificate of completion will be awarded at
-- the end of the course. That and $1.75 will get you a cup of Starbucks.

Irv

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

Search



Quick Links

User menu

Not signed in.

Misc Menu