Mark Volt February 2016

Variable redefinition warning

I got warning in the following code:

while true
  10.times { print "-"}
  puts "-"
  print "Температура по Цельси: "
  C = gets.to_i
  if (C < -273.15)
    print "Ошибка: температура меньше абсолютного нуля\n"
  else
    print "Температура: #{C + 273.15} по Кельвину\n"
  end
end

When running, I get:

test.rb:7: warning: already initialized constant C
test.rb:7: warning: previous definition of C was here

How can I redefine it without error? Why is it defined as a constant and not a variable?

Answers


sawa February 2016

Why is it defined as a constant and not a variable?

Because C starts with a capital.

How can I redefine it without error?

Use a local variable, which starts with small letter, for example: c.

Post Status

Asked in February 2016
Viewed 1,007 times
Voted 4
Answered 1 times

Search




Leave an answer