School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,363 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,432 people online right now. Registration is fast and FREE... Join Now!




Help with a Craps Game program!

 

Help with a Craps Game program!, Trying to write a Craps Game and failing miserably.

ruby4life

20 Apr, 2009 - 12:55 PM
Post #1

New D.I.C Head
*

Joined: 20 Apr, 2009
Posts: 1

Hi,
I was having some trouble with my code for a Craps game. The Code is pretty elementary, we don't have to do any betting. I don't understand two things:
1. How to have 2 whiles
ex. while point != 5 *and* while point !=6
2. Why my code won't work. I tried removing the second while statement and it still didn't work. Any ideas?
CODE

puts "Welcome to Craps"
roll1 = 2 + rand(6) + rand(6)
if roll1 == 7
puts "Your roll is " + roll1.to_s + ". You win!"
if roll1 == 11
puts "Your roll is " + roll1.to_s + ". You win!"
if roll1 == 2
puts "Your roll is " + roll1.to_s + ". You lose!"
if roll1 == 3
puts "Your roll is " + roll1.to_s + ". You lose!"
if roll1 == 12
puts "Your roll is " + roll1.to_s + ". You win!"
else
puts "Your roll was " + roll1.to_s + ". Roll again!"
point = 2 + rand(6) + rand(6)
if point == 7
puts "Your roll is " + point.to_s + ". You lose!"
if point == roll1
puts "Point is " + point.to_s + ". You win!"
while point != roll1, 7 do
puts "Your roll is " + point.to_s + ". Roll again!"
roll2 = 2 + rand(6) + rand(6)
if roll2 == 7
puts "Your roll is " + point.to_s + ". You lose!"
if roll2 == roll1
puts "Point is " + point.to_s + ". You win!"
end


User is offlineProfile CardPM
+Quote Post


JackOfAllTrades

RE: Help With A Craps Game Program!

23 Apr, 2009 - 11:46 AM
Post #2

I exist to Google your problems.
Group Icon

Joined: 23 Aug, 2008
Posts: 4,948



Thanked: 423 times
Dream Kudos: 50
Expert In: Being annoyed with lazy people.

My Contributions
This is a couple of days old, and I felt like messing around a little, so here's my attempt:

ruby
def init
puts "Welcome to Craps"
srand Time.now.tv_sec
end

def getroll
2 + rand(6) + rand(6)
end

init

roll1 = getroll
puts "Your roll was " + roll1.to_s
case roll1
when 7, 11, 12
puts "You win!"
exit
when 2, 3
puts "You lose!"
exit
else
puts "Roll again!"
end

point = getroll
puts "Point is " + point.to_s
case point
when 7
puts "You lose!"
exit
when roll1
puts "You win!"
exit
end

roll2 = 0
while point != roll2
roll2 = getroll
puts "Your roll is " + roll2.to_s
case roll2
when 7
puts "You lose!"
exit
when point
puts "You win!"
exit
else
puts "Roll again"
end
end

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 08:36PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month