First time programmer and I am confused as to why my ruby code is not giving the result I want. I wrote a simple program to simulate rolling different multi-sided dice.
d4 = rand (1..4)
d6 = rand (1..6)
d8 = rand (1..8)
d12 = rand (1..12)
d20 = rand (1..20)
percent = rand (1..100)
puts "Which dice would you like to roll?"
which_dice = gets.chomp
puts "You rolled a #{which_dice}!"
The first six lines define each dice to output a random number between 1 and the number of sides of the dice has. I then ask the user to input the dice they want rolled with the gets method and then out put the result with the last line.
The problem is that when the last line is executed it puts out "You rolled a (what ever the user inputs with the gets method as a string)!". For example, when the user inputs d8 when prompted it would puts "You rolled a d8!" instead of the actually random between 1 and 8 that I want. How can I have it so it puts an actual random number?