Computer Science Canada

security system program

Author:  amir20001 [ Fri May 16, 2008 8:26 pm ]
Post subject:  security system program

i have started on this but i don't fully understand how the parallelget function works

here is what i have so far any help would be appreciated


code:

var val1, val2, val3, val4, val5 : boolean
loop
    delay (1000)
    const val : int := parallelget % Read in the set of pin values
    cls
    put "Pin 10 is: ", (val div 64) mod 2
    get val1
    put "Pin 11 is: ", (val div 128) mod 2
    get val2
    put "Pin 12 is: ", (val div 32) mod 2
    get val3
    put "Pin 13 is: ", (val div 16) mod 2
    get val4
    put "Pin 15 is: ", (val div 8) mod 2
    get val5
end loop

if val1 := 1 then
    parallelput (4)
    if val2 := 1 then
        parallelput (8)
        if val3 := 1 then
            parallelput (16)
            if val4 := 1 then
                parallelput (32)
                if val5 := 1 then
                    parallelput (64)
                    if val5 := 1 then
                        parallelput (128)
                    else
                        parallelput (0)
                    end if

Author:  syntax_error [ Fri May 16, 2008 11:41 pm ]
Post subject:  Re: security system program

amir20001 wrote:


code:


if val1 := 1 then
    parallelput (4)
    if val2 := 1 then
        parallelput (8)
        if val3 := 1 then
            parallelput (16)
            if val4 := 1 then
                parallelput (32)
                if val5 := 1 then
                    parallelput (64)
                    if val5 := 1 then
                        parallelput (128)
                    else
                        parallelput (0)
                    end if



I am not sure about your parallelget issue but
not 100% sure but I think you should have end if after each if statement

Author:  gitoxa [ Fri May 16, 2008 11:57 pm ]
Post subject:  RE:security system program

if val1 = 1 then
as opposed to
if val1 := 1 then

Author:  Nick [ Sat May 17, 2008 12:01 am ]
Post subject:  RE:security system program

err... why are you declaring variables in an if statement, does that even run?

EDIT: also the program will never leave the loop reaching the bottom statements

Author:  Sean [ Sat May 17, 2008 9:10 am ]
Post subject:  Re: security system program

Also, change your if statements. You don't need to use new if statments all the time, you can continue an if statment by adding elsif to it. Like so:

Turing:

if val1 = 1 then
    parallelput (4)
elsif val2 = 1 then
    parallelput (8)
elsif val3 = 1 then
    parallelput (16)
elsif val4 = 1 then
    parallelput (32)
elsif val5 = 1 then
    parallelput (64)
elsif val5 = 1 then
    parallelput (128)
else
    parallelput (0)
end if

Author:  Nick [ Sat May 17, 2008 10:01 am ]
Post subject:  RE:security system program

also use arrays, that if statement can be a single for loop + if

Author:  amir20001 [ Sat May 17, 2008 11:21 am ]
Post subject:  Re: RE:security system program

nick @ Sat May 17, 2008 12:01 am wrote:
err... why are you declaring variables in an if statement, does that even run?

EDIT: also the program will never leave the loop reaching the bottom statements


i didn't know u couldn't do that, and it dose not run thx for ur help

Author:  amir20001 [ Sat May 17, 2008 11:27 am ]
Post subject:  Re: security system program

thx a lot every one i got it working Smile


: