Hi all,

I'm new to the programming world, so much of this stuff is still pretty
foreign to me.

I've created a 'roll_dice.rb' program that draws on the 'die.rb' model.
When the roll_dice program is run, the user is simply prompted to type
'roll' to roll the dice and get a result. Typing 'quit' exits the
program.

I'd like to expand the functionality of this program such that when the
program is run, the user is first prompted to enter in how many dice
they would like to roll. After answering, the user would then type
'roll' and receive back the same number of answers as number of dice.
i.e. :

How many dice would you like to roll?
> 2
Type 'roll' to roll your dice.
>roll
3
2
Type 'roll' to roll your dice.
>roll
6
4


The thing is, I'm not sure how to add that kind of functionality to my
program yet. Thoughts and suggestions are appreciated. Thanks!


Here is my current code (I've also included it as an attachment):

die.rb

Class Die
  def rolled_dice
    1 + rand(6)
  end
end

roll_dice.rb

require_relative 'die'

@die = Die.new

while true
  puts "Type 'roll' to roll the dice."
  answer = gets.chomp
  if answer == 'roll'
    puts @die.rolled_dice
  elsif answer == 'quit'
    break
  else
    puts "Please type 'roll' or 'quit'."
  end
end

Attachments:
http://www.ruby-forum.com/attachment/8742/die.rb
http://www.ruby-forum.com/attachment/8743/roll_dice.rb


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