Having trouble with randomisation

I want my program to say a diffrent maths question everytime the user
goes through the cycle, however it just does the same one :frowning: What can I
do to achive my goal?

V2 = 1 + rand(22)

V1 = 1 + rand(22)

class Die

聽聽def roll
聽聽聽聽1 + rand(22)
聽聽end

end

def hello
聽聽聽聽puts 'whats your name'
聽聽聽聽name = gets.chomp
聽聽聽聽puts "Hello ". + name
聽聽end

def maths_question
聽聽puts 'Whats the sum of ' + V2.to_s + ' and ' + V1.to_s + ' ?'
聽聽youSAY = gets.chomp
聽聽while youSAY != CorrectA.to_s
聽聽聽聽puts 'Wrong, please try again'
聽聽聽聽youSAY = gets.chomp
聽聽end
end

def maths_congrats
聽聽puts 'Congrats, you got ' + CorrectA.to_s + ', which was the correct
answer!'
end

hello
puts 'Do you want to do maths questions?'
domath = gets.chomp
while domath == 'yes'

CorrectA = V1.to_i + V2.to_i

maths_question
maths_congrats
puts 'Do you want to do more?'
domath = gets.chomp
end

路路路

--
Posted via http://www.ruby-forum.com/.

V1 and V2 are constants calculated one time at the beginning of your
script. If you want to loop through your logic with different values
for V1 and V2 each time, you need to recompute them each time through
your loop.

When you do that, you should name them with a lower case first letter so
that ruby does not treat them as constants. Doing that will require
that you rework your logic so that you can pass in these dynamically
generated values to all of your methods that use them.

-Jeremy

路路路

On 12/12/2010 11:55 AM, Deza Awesome wrote:

I want my program to say a diffrent maths question everytime the user
goes through the cycle, however it just does the same one :frowning: What can I
do to achive my goal?