+ 1
Problem with = and ==
I'm writing a program and I'm having problems with these: if c = 'binary' then while a >= 1 do b = b + String(a % 2) a = a / 2 end b.reverse puts b This outputs the correct answer, but displays this error: ..\Playground\:5: warning: found = in conditional, should be == When I fix this and replace = with == I get no error, but no output either.. What's the problem here? :/
9 Answers
+ 5
Rewrite that if statement.
if c == 'binary'
And, considering this is Ruby, then your while loop shouldn't have a do at the end of it.
+ 4
Not with Ruby, no. The then hasn't been in any languages (and as far as I know, QBASIC64 was the last major language to use it.)
+ 3
You have one more problem. You have an end for your while loop, but not your if statement.
+ 1
It has no then?
+ 1
I did as you said, but I still get no output...
+ 1
I'm learning in school to work with Delphi, and I'm pretty sure it does have then...
+ 1
I have an end, but that's later in code
+ 1
Heres the whole code
x = gets
a = gets.to_i
b = ''
if x == 'binary'
while a >= 1
b = b + String(a % 2)
a = a / 2
end
b.reverse
puts b
elsif x == 'octal'
while a >= 1
b = b + String(a % 8)
a = a / 8
end
b.reverse
puts b
end
+ 1
oh, i found the problem. i need to use gets.chomp for x. and i was using only gets
can you tell me difference between those. i dont understand the explanation on sololearn course... :/