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

Username:   Password: 
 RegisterRegister   
 Craps Game, Beginner Coder :(
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
thuren12




PostPosted: Thu Nov 19, 2009 8:01 pm   Post subject: Craps Game, Beginner Coder :(

What is it you are trying to achieve?
Create a craps game

What is the problem you are having?
How do I continuously roll using a randint function to keep rolling DIFFERENT numbers?

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:

var d1, d2 : int
var point, sum : int
randint (d1, 1, 6)
randint (d2, 1, 6)
point := d1 + d2
sum := d1 + d2

loop
    delay (500)
    put d1, ",", d2
    exit when sum = 2 or sum = 3 or sum = 12 or sum = 7 or sum = 11

end loop

if sum = 2 or sum = 3 or sum = 12 then
    put "Sorry, you lost!"
elsif sum = 7 or sum = 11 then
    put "Grats, you won!"
else
    put d1, ",", d2
end if


edited it a little so you can understand what im trying to get at better.
Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
D_homes




PostPosted: Thu Nov 19, 2009 8:10 pm   Post subject: RE:Craps Game, Beginner Coder :(

Well for starters the randint would have to be in the loop, so it is constantly changing and not just staying the same value.
thuren12




PostPosted: Thu Nov 19, 2009 8:12 pm   Post subject: Re: Craps Game, Beginner Coder :(

Oh awesome, thanks didn't think of that. Any way to shorten exit when or if statements? Like how mine is super long because of all the conditions?
belarussian




PostPosted: Thu Nov 19, 2009 9:01 pm   Post subject: RE:Craps Game, Beginner Coder :(

ya put the rand int into the loop that should help and soon io will post the porogramm with the comments and you should try to do that it really helps
D_homes




PostPosted: Thu Nov 19, 2009 9:23 pm   Post subject: Re: RE:Craps Game, Beginner Coder :(

belarussian @ Thu Nov 19, 2009 9:01 pm wrote:
ya put the rand int into the loop that should help and soon io will post the porogramm with the comments and you should try to do that it really helps


Shouldn't you let him figure it out on his own? Thats the only way he'll learn.
Turing_Gamer




PostPosted: Thu Nov 19, 2009 9:35 pm   Post subject: Re: Craps Game, Beginner Coder :(

I learned myself that you have to redefine the number after it randomizes for another number...

Example would be a dice game!

Unless there is another quicker way which I don't know of...
Tony




PostPosted: Thu Nov 19, 2009 9:48 pm   Post subject: Re: Craps Game, Beginner Coder :(

Turing_Gamer @ Thu Nov 19, 2009 9:35 pm wrote:
you have to redefine the number after it randomizes for another number.. Unless there is another quicker way which I don't know of...

I don't think I understand what you are saying.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
thuren12




PostPosted: Fri Nov 20, 2009 8:28 am   Post subject: Re: Craps Game, Beginner Coder :(

Thank you for all the help guys. Appreciate it, I got my computer science class first period anyways so I'll ask my teacher more questions Razz. It just drove me crazy last night.
Sponsor
Sponsor
Sponsor
sponsor
belarussian




PostPosted: Fri Nov 20, 2009 8:54 pm   Post subject: RE:Craps Game, Beginner Coder :(

OK LOOK WHEN YOU USE COMMENTS YOU ACTUALLY UNDERSTAND WHAT YOU ARE DOING AND DONT PUT COMMENTS IF YOU DONT UDERSTAND!!!!!!!!!!!
belarussian




PostPosted: Fri Nov 20, 2009 8:57 pm   Post subject: RE:Craps Game, Beginner Coder :(

You dont necesarally need to put the rand int into the loop because it wont exit the first loop untill the sum thing is coorect so it will goback and do it again iuntil sum is equal
Tony




PostPosted: Fri Nov 20, 2009 9:08 pm   Post subject: Re: RE:Craps Game, Beginner Coder :(

belarussian @ Fri Nov 20, 2009 8:54 pm wrote:
DONT PUT COMMENTS IF YOU DONT UDERSTAND!!!!!!!!!!!

Are you referring to me?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Turing_Gamer




PostPosted: Sun Nov 22, 2009 5:00 pm   Post subject: Re: Craps Game, Beginner Coder :(

Sry Tony, this is what i meant...
Turing:
var num := Rand.Int (1, 6)
var c : string := "?"
loop
      put " You rolled a ", num, "!"
      put " Would you like to roll again?"
      get c
      if c = "yes" then
            num := Rand.Int (1, 6) %<------- Right here
      elsif c = "no" then
            quit
      else
            put "Invalid answer!"
      end if
end loop
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  [ 12 Posts ]
Jump to:   


Style:  
Search: