david said the following on 18/06/06 13:01:
> On Sat, 2006-06-17 at 17:35 +1000, Vini Engel wrote:
>> Hi Guys,
>>
>> I am coming in a bit late ... my code is below.
>>
>> amount = ARGV[0].to_f
>>
>> remainder = amount % 5
>> known_amount = amount - remainder
>>
>> if remainder <= 2
>> puts
>> puts "Entered amount is #{amount}"
>> puts "Amount being rounded down is #{remainder}"
>> puts "Total final amount #{amount}"
>> puts
>> else
>> puts
>> puts "Entered amount is #{amount}"
>> puts "Amount being rounded up is #{remainder}"
>> puts "Total final amount #{amount + 5}"
>> puts
>> end
>>
>
> * strictly speaking this is incorrect because the rounding rule for this
> exercise is to round UP for > 2 and down for <= 2
Well, I must say that I agree with you. However what other results could
we have here? If is is not less or equal 2 it will be greater but will
never go beyond 5. I agree it could be clearer in the code though.
> * I think the lines <puts "Total final..... etc"> should be
>
> puts "Total final amount #{known_amount}"
> ^^^^^^
This was my mistake!
Adding 5 to the entered amount doesn't help much I suppose ;( I made the
mistake once above and then copied and pasted the line and didn't check
just ran to see what the output was.
The correct way would be:
if remainder <= 2
puts
puts "Entered amount is #{amount}"
puts "Amount being rounded down is #{remainder}"
puts "Total final amount #{known_amount}"
# now we show the the entered amount - the reminder.
puts
else
puts
puts "Entered amount is #{amount}"
puts "Amount being rounded up is #{remainder}"
puts "Total final amount #{known_amount + 5 }"
# here we add 5, rounding it up to the next $5
puts
end
How does it look like now?
>> There will be more to come this weekend, I will be doing my home work
>> and posting the stuff here. Sorry for not being able to comment on
>> anyone's code yet.
>
> too busy watching the football! ;-)
> (me too)
Yeah, today it is going to be hard work for both teams!
If Brazil plays as "hard" as they played against Croatia, Australia is
going to kick their asses. Honesty it wouldn't be too bad as perhaps it
would wake them up and make them work harder. And I would be happy to
see Australia winning anyway :)
Just don't what I am going to do as I will have to work tomorrow
morning, in Brazil it is a kind of public holiday when the game is on so
no-one works.
Vini
_______________________________________________
coders mailing list
[email protected]
http://lists.slug.org.au/listinfo/coders