Hockey.ex

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

Here's what I have so far.  I added the while loop to hockey.ex to stop the
program from instantly dumping out under Windows 95, but the yes/no input
doesn't yet work.  Any ideas?

-- file dialog.e
-- enables simple text input and output

include get.e
include graphics.e

global function input(sequence prompt)
-- print a message and read in a number
-- returns the number, that can either be an integer or an atom(float)
sequence input, curpos
    input = {1, 0}              -- this initializes the variable input with
                                -- values that are *not* valid
    puts(1, prompt)             -- put message on screen
    while input[1] do           -- repeat until valid number
        curpos = get_position() -- read current cursor position
        input = get(0)          -- read from the keyboard
        position(curpos[1], curpos[2])  -- back to position if not valid
    end while
    puts(1, '\n')               -- to start on a new line when back from
function
    return input[2]             -- the second element of input is returned
                                -- and should contain a valid number
end function    -- input()

-- Input of a string with a prompt:

global function prompt_in(sequence prompt)
sequence in_string              -- to read in the input
    puts(1, prompt)             -- put prompt (question) on the screen
    in_string = gets(0) -- read string input from the keyboard
    puts(1, '\n')               -- to start on a new line when back from
                                -- function
        -- return the input string now, but strip off the last character,
        -- since that is a 'new line' character (ASCII 10)
    return in_string[1..length(in_string) - 1]
end function    -- prompt_in()

--EOF

-- file hockey.ex
-- reads in and prints team results.

include dialog.e

sequence team
atom halt
integer won, lost, tie, points

halt = '1'

while halt = '1' do

team = prompt_in("\t Team: ")
won = input("\t Won : ")
lost = input("\t Lost: ")
tie = input("\t Tie : ")
points = won * 2 + tie
puts(1,"\t Team \t \t Won Lost Tie Points \n\n")
printf(1,"\t %-14s %3d %4d %3d %6d \n", {team} & won & lost & tie & points)

halt = input ("\t Do another? 1 = yes 2 = no ")

end while
-- EOF

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

Search



Quick Links

User menu

Not signed in.

Misc Menu