Computer Science Canada

need help with procdures

Author:  someguy123 [ Thu Feb 01, 2007 8:05 pm ]
Post subject:  need help with procdures

Quote:
var card : array 1 .. 52 of int
var cardcheck : array 1 .. 52 of boolean
var cardnum : array 1 .. 52 of int
var num : int
var counter : int := 1
var guess : string

for i : 1 .. 52
card (i):= Pic.FileNew ("cards/" + intstr (i) + ".jpg")
cardcheck (i) := true
end for

procedure Dealing
loop
randint (num, 1, 52)
Pic.Draw (card (num), 0, 0, picCopy)
exit when cardcheck (num) = true
end loop
cardcheck (num) := false
cardnum (counter) := (num)
counter := counter + 1
end Dealing

procedure Guess
locate (1,1) put "Higher or lower?"
get guess
end Guess

procedure Compare
if cardnum (counter) > cardnum (counter-1) and guess = "lower" then
put "You are right."
elsif cardnum (counter) < cardnum (counter-1) and guess = "higher" then
put "You are right."
else
put "Your are wrong."
end if
end Compare

Dealing
Guess
Dealing
Compare


during my compare procedure i dont get any value on any variable so it doesnt run correctly, andyone can give me any advice on how to fix it?

Author:  CodeMonkey2000 [ Thu Feb 01, 2007 8:39 pm ]
Post subject:  Re: need help with procdures

My guess is that cardnum (counter) never gets assigned a value.

Author:  someguy123 [ Thu Feb 01, 2007 8:42 pm ]
Post subject:  Re: need help with procdures

any idea how to fix that?

Author:  CodeMonkey2000 [ Thu Feb 01, 2007 9:20 pm ]
Post subject:  RE:need help with procdures

try cardnum (counter-1) > cardnum (counter-2)

Author:  someguy123 [ Thu Feb 01, 2007 9:49 pm ]
Post subject:  Re: RE:need help with procdures

spearmonkey2000 @ Thu Feb 01, 2007 9:20 pm wrote:
try cardnum (counter-1) > cardnum (counter-2)


how would that make a difference..

Author:  runhardndie [ Tue Feb 06, 2007 4:42 pm ]
Post subject:  Re: need help with procdures

Just choose 2 different numbers in your deal procedure. I reordered your program for you to look at..(see attached)

Author:  CodeMonkey2000 [ Tue Feb 06, 2007 10:42 pm ]
Post subject:  Re: RE:need help with procdures

someguy123 @ Thu Feb 01, 2007 9:49 pm wrote:
spearmonkey2000 @ Thu Feb 01, 2007 9:20 pm wrote:
try cardnum (counter-1) > cardnum (counter-2)


how would that make a difference..

because look at where this statement is: counter := counter + 1 this is a off-by-one error.
If you want your way to work do:
Turing:
var num : int
var counter : int := 0
var guess : string

for i : 1 .. 52
    card (i) := Pic.FileNew ("cards/" + intstr (i) + ".jpg")
    cardcheck (i) := true
end for

procedure Dealing
    loop
        randint (num, 1, 52)
        Pic.Draw (card (num), 0, 0, picCopy)
        exit when cardcheck (num) = true
    end loop
    counter := counter + 1
    cardcheck (num) := false
    cardnum (counter) := (num)
end Dealing

procedure Guess
    locate (1, 1)
    put "Higher or lower?"
    get guess
end Guess

procedure Compare
    if cardnum (counter) > cardnum (counter - 1) and guess = "lower" then
        put "You are right."
    elsif cardnum (counter) < cardnum (counter - 1) and guess = "higher" then
        put "You are right."
    else
        put "Your are wrong."
    end if
end Compare

Dealing
Guess
Dealing
Compare


: