J
John Maclean
This block of code works and it's easy to see why:-
def add_two_num
p "gimme two numbers. first : "
x = gets.chomp
p "second : "
y = gets.chomp
out = x.to_i + y.to_i
p out
end
add_two_num
This next lot --doesn't-- and I get the feeling that it has something to
do with scope, maybe within the case block. Am I right?
def
test_gets_positive p "gimme a number : "
ask = gets.chomp
n = ask.to_i
case
when n < 0
puts "this number is -ve. i ain't gonna play no more! STOP!"
exit
when n = 0
print " this number is +ve! this it\'s square:"
p n*n
end
end
test_gets_positive
wtf has happened to n?
Regards,
John Maclean
MSc (DIC)
+44 7739 171 531
def add_two_num
p "gimme two numbers. first : "
x = gets.chomp
p "second : "
y = gets.chomp
out = x.to_i + y.to_i
p out
end
add_two_num
This next lot --doesn't-- and I get the feeling that it has something to
do with scope, maybe within the case block. Am I right?
def
test_gets_positive p "gimme a number : "
ask = gets.chomp
n = ask.to_i
case
when n < 0
puts "this number is -ve. i ain't gonna play no more! STOP!"
exit
when n = 0
print " this number is +ve! this it\'s square:"
p n*n
end
end
test_gets_positive
wtf has happened to n?
Regards,
John Maclean
MSc (DIC)
+44 7739 171 531