Hi all
I'm new to programming, and new to Ruby.
I've written a little program listed below, a very simple math test, to
get into the swing of things.
My question; could someone point out what I could do to make this more
elegant, and any mistakes etc. - basically a critique would be most
welcome.
I think this would give me some real help in understanding what I need
to learn next.
Many thanks for your time
s.
puts "Please enter your name:"
firstname = gets.chomp
number1 = rand(100)
number2 = rand(100)
operatorarray = ["+", "-"]
randop = rand(2)
getoperator = operatorarray[randop]
question = number1.to_s + getoperator + number2.to_s
answer = eval "#{number1} #{getoperator} #{number2}"
puts "Welcome to MathTest!"
puts "#{firstname}" + ", here is your first question:"
puts question
usranswer = gets.chomp
if
eval "#{usranswer} == #{answer}"
puts "Correct!"
else
puts "Incorrect. The answer is " + "#{answer}"
end
···
--
Posted via http://www.ruby-forum.com/.