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

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




PostPosted: Wed Jan 03, 2007 2:18 pm   Post subject: I need some help

I'm trying to write a program for this Posted Image, might have been reduced in size. Click Image to view fullscreen.
But I can't seem to get it working properly
Here's what I have so far
code:
var randnum1, randnum2 : int
var  input : string
var games : int
var rolls : int := 0
var tries : int := 0
loop
    put "Enter the number of games to be played: " ..
    get input
    if strintok (input) then
        games := strint (input)
        exit
    else
        put "That's not a number, please try again"
    end if
end loop

randint (randnum2, 1, 12)
for gamenum : 1 .. games
    loop
        randint (randnum1, 1, 12)
        rolls := rolls + 1
        delay (1000)
        tries:= tries + 1       
        put "game", rolls

        delay (1000)
        put "Roll ", tries, ":", randnum1

        if ((randnum1 = 7) and (rolls = 1)) then
            delay (1000)
            put "Iwin"
            exit
        elsif ((randnum1 = 11 and (rolls = 1))) then
            delay (1000)
            put "winner"
            exit
        elsif ((randnum1 = 2 or randnum1 = 12)) and (rolls = 1) then
            delay (1000)
            put "lose"
            exit
        elsif ((randnum1 = randnum1)) and ((rolls > 1)) then
            delay (1000)
            put " youwin"
            exit
        elsif ((randnum1 = 7) and (rolls > 1)) then
            delay (1000)
            put "you lose"
            exit


        end if
    end loop
end for


I know some of it is pretty bad, but it made sense when I was writing it. Some parts work and some don't. Any help I receive will be greatly appreciated.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Wed Jan 03, 2007 4:11 pm   Post subject: (No subject)

Welcome to CompSci.ca!

First, I'd just like to point out that we don't do people's homework here. That's not what we're for. I realize that's probably not what you wanted, but the fact that you've posted your assignment sheet means the topic is in the air, so it needed to be said.

Second, it's good that you posted some code. To make it easier for us to help you, however, it'd be great if you could specify what part you're having trouble with. Talk a little bit about your code.

I'll point out one thing that's wrong with your code: you're using randint to get a random number between 1 and 12. That's not the same as rolling two six sided dice, because the probabilities are different. With 2 six sided dice, the chance of getting a 7 is higher than any other number, but with your randint method, the chance of getting a 7 is the same as any other number.

Oh, one more thing: please post descriptive topic titles. It helps keep things ordered, and actually helps you to get help. "Craps" would have sufficed. Thanks Smile
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  [ 2 Posts ]
Jump to:   


Style:  
Search: