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

Username:   Password: 
 RegisterRegister   
 procedures
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SwAnK




PostPosted: Tue Apr 19, 2005 6:59 pm   Post subject: procedures

hey, i want to make it so you roll 5 dice, and then if you have 3 ones, you get 1000pts. Here is what i have done so far, but it does not work properly at all. Could somone please help me.

code:
var numply : int
var players : array 1 .. 4 of string
var name : int := 0
var roll : array 1 .. 5 of int
var count, w : int := 0
var str1, str2, str3, str4, str5 : int
var done : boolean := false
var roll1, roll2, roll3, roll4, roll5 : int

proc rolling
    for a : 1 .. 5
        roll (a) := Rand.Int (1, 6)
randint (roll (a), 1, 6)
put "Rolled ", roll (a)


    end for

end rolling

put "Please enter the number of players, 4 max"
get numply
loop
    name += 1
    put "enter names"

    get players (name) : *
    exit when name = 4 or name = numply
end loop


procedure check
    for a : 1 .. 5
        for b : 1 .. 5
            for c : 1 .. 5
                if roll (a) = 1 and roll (b) = 1 and roll (c) = 1 then
                    count := count + 1000
                    done := false
                end if
                exit when done
            end for
            exit when done
        end for
        exit when done
    end for
end check
rolling

check





put " score is ", count, ""

for i : 1 .. name
    put players (i), ":             ", count
end for
Sponsor
Sponsor
Sponsor
sponsor
Bacchus




PostPosted: Tue Apr 19, 2005 7:27 pm   Post subject: (No subject)

why so many fors?
code:
fcn check(roll:array 1..* of int):boolean
    var count:int:=0
    for i:1..5
        if roll(i)=1 then
            count+=1
        end if
    end for
    if count>=3 then
        result true
    else
        result false
    end if
end check
SwAnK




PostPosted: Tue Apr 19, 2005 7:45 pm   Post subject: (No subject)

ok thanx, but how do i get it so it "checks" my procedure?? each time i put check it says syntax error expected :=.

heres what i have ( i'm just trying to get it to work then ill put it into the one above)

code:
var roll : array 1..5 of int
fcn check(roll:array 1..* of int):boolean
    var count:int:=0
    for i:1..5
        if roll(i)=1 then
            count+=1
        end if
    end for
    if count>=3 then
        result true
    else
        result false
    end if
end check

proc rolling

    for i : 1 .. 5
        roll (i) := Rand.Int (1, 6)
        put "Rolled ", roll (i)
       
       
    end for
    check
end rolling
rolling
check
Bacchus




PostPosted: Tue Apr 19, 2005 9:12 pm   Post subject: (No subject)

the one i made was a function not a procedure
Martin




PostPosted: Tue Apr 19, 2005 11:08 pm   Post subject: (No subject)

I'm not going to delete this post because of the replies it's generated, but please edit it and give it a more descriptive title.
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  [ 5 Posts ]
Jump to:   


Style:  
Search: