Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 need help with procdures
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
someguy123




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: 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.
someguy123




PostPosted: Thu Feb 01, 2007 8:42 pm   Post subject: Re: need help with procdures

any idea how to fix that?
CodeMonkey2000




PostPosted: Thu Feb 01, 2007 9:20 pm   Post subject: RE:need help with procdures

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




PostPosted: 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..
runhardndie




PostPosted: 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)


Card.t
 Description:

Download
 Filename:  Card.t
 Filesize:  1.02 KB
 Downloaded:  94 Time(s)

CodeMonkey2000




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: