I have the code, that will generate random numbers, unless the generated random number is 0. When the result is 0, the loop breaks.
So when the loop breaks, I want a code, that keeps adding the random numbers that kept generated and display it at the last. Can I do that in ruby?
def batting
loop do
runs = [0,1,2,3,4,5,6]
myruns = runs.shuffle.first
Newscore =
puts "Press W to hit a shot"
user_input = gets.chomp
while user_input.include? "W"
puts myruns
until myruns == 0
break
Score = Score + myruns
break
This is throwing Dynamic Constant assignment
error at Score = Score + myruns
which I basically thing, its wrong, since the myruns
keep changing at every generated event?
So, I would want to create a new variable, that would store the total of all the random numbers generated until the generated random number is 0.
Could anyone help?
Aucun commentaire:
Enregistrer un commentaire