Craps Game, Beginner Coder :(
Author |
Message |
thuren12
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
D_homes
![](http://compsci.ca/v3/uploads/user_avatars/14338014624af713596354e.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
thuren12
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
belarussian
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
D_homes
![](http://compsci.ca/v3/uploads/user_avatars/14338014624af713596354e.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Turing_Gamer
![](http://compsci.ca/v3/uploads/user_avatars/8617055374bcc8b48c6d4f.png)
|
Posted: 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... |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: 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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
thuren12
|
Posted: 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 . It just drove me crazy last night. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
belarussian
|
Posted: 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!!!!!!!!!!! |
|
|
|
|
![](images/spacer.gif) |
belarussian
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: 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? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Turing_Gamer
![](http://compsci.ca/v3/uploads/user_avatars/8617055374bcc8b48c6d4f.png)
|
Posted: 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 |
|
|
|
|
|
![](images/spacer.gif) |
|
|