From: Christopher Dicely Date: 2010-09-07T09:16:48+09:00 Subject: Re: Dice Roller On Mon, Sep 6, 2010 at 5:01 PM, Hd Pwnz0r wrote: > It won't work. It's odd. It won't stop and it won't add a number onto x > so it would say > "Roll 1: 5 > Roll 2: 3" > etc > > It just repeats "Roll 1: (random number)". > > Also, is there a way for me to add one to the rand function so it won't > get a zero? > > Attachments: > http://www.ruby-forum.com/attachment/5009/dice.rb > I've added comments to your code pointing to areas of concern: puts "How many dice do you want to roll?" roll = gets.chomp num_rolls = roll # Why are you assigning to num_rolls here? You never use this variable! y = 0 # "y" is a bad name for a variable, generally. What is this variable for? Why is it 0? x = y.to_i + 1 # What is "x" for? Why are you calling to_i on something you just assigned an integer value, so you should know you don't need this? while x <= roll.to_i # since you never assign to x, if it is ever true, it will always be true and you'll never escape from the loop. puts "Roll " + x.to_s + ": " + rand(max=6).to_s # you are assigning 6 to max -- a variable you never use anywhere else -- and then immediately passing that to rand. Why? end