D'oh, sorry Yaroun,
I missed the other mistake staring me in the face - it's the way that 'div' has been used.
There are two ways to fix this one.
1) Replace 'div' with '/' - so long as the numbers either side of the divide are integers, the result will also be an integer...
2) 'div' is a 'method'', not an operator in the sense that most other languages would use it.This fix (and that sentence!) will probably seem very strange at first to someone coming from Pascal - but it shows a key part of Ruby syntax that will become very important...
You'll see here that I've kept the 'div' but I've bracketed together the numbers, and put a dot between the first set of numbers and the 'div'.
This is the usual way of doing things in Ruby most of the time - things like '+', '=' etc. that don't use the 'dot' notation, are actually special cases that are included to make writing maths a little bit easier ("syntax sugar")
The general way of doing something to an object (variable, value) is...
this_object.do_something(parameters)"this_object" is the thing you want to do something to - i.e. in this case the 'temp' stuff.
"do_something" after the dot is the action that you want to perform - e.g. 'div'
"(parameters)" are any other values that are needed to work out how to do the "do_something" - e.g. the number you want to divide by.
For example, to round a number to two decimal places, you would write...
rounded = my_number.round(2)In most other languages, you'd probably think of this as something like calling a function or procedure - in Ruby, they are called 'methods', and every single thing you can do to a value is really a method. But there's a slight difference...
A function call in most languages looks something like...
a = div(x,y)...whereas in Ruby, it would be...
a = x.div(y)The best way that I've heard this explained is to think of methods as a message that you send to something - "tell x to use its 'div' method with 'y' as the divisor". When reading about Ruby programming you will often see that first value 'x' referred to as the "receiver", because it's the one receiving the "do this now" messages.
Just to be even more confusing, the brackets around the parameters are usually optional...
rounded = my_number.round 2divided = my_number.div 2Personally, I nearly always use the brackets, and most 'Rubyists' recommend this, because it makes the syntax clearer - just using spaces can make it unclear where values, methods and parameters begin and end, and can even confuse the parser sometimes.
(NB - I love that DSPr included Ruby, but their examples show a whole load of dodgy ways of writing it that the Ruby 'style' standards recommend you don't use!).
If that all seems very confusing, don't worry, you are not alone. I come from a procedural language background too, and all this "object oriented" stuff still seems very weird!