-2
All right? I’m doing a challenge on Ruby and the def’s need to be the way it is in the code I’m gonna send. The division by 0 needs to return with the message "Oops! Zero as divisor" I’ve been trying for a while but I still can’t get this result, always presents me the mistake
An error occurred while loading ./spec/calculadora_spec.rb.
Failure/Error: require 'calculadora'
SyntaxError:
/home/leticia/Documentos/campos_code/calculator/lib/calculadora.rb:18: syntax error, unexpected `end', expecting end-of-input
# ./spec/calculadora_spec.rb:2:in `require'
# ./spec/calculadora_spec.rb:2:in `<top (required)>'
No examples found.
Finished in 0.00004 seconds (files took 0.26173 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
My code is like this:
def soma(primeiro_numero, segundo_numero)
primeiro_numero+segundo_numero
end
def subtracao(primeiro_numero, segundo_numero)
primeiro_numero-segundo_numero
end
def multiplicacao(primeiro_numero,segundo_numero)
primeiro_numero*segundo_numero
end
def divisao(primeiro_numero,segundo_numero)
primeiro_numero / segundo_numero
end
ZeroDivisionError
puts "Opa! Zero como divisor"
end
Can you give me a hand? I made some changes as well and my last code became so
def divisao(primeiro_numero,segundo_numero)
if segundo_numero != 0
return primeiro_numero/segundo_numero
elsif primeiro_numero = 0
puts 'Opa! Zero como divisor'
else segundo_numero = 0
puts 'Opa! Zero como divisor'
end
But it really doesn’t work yet. I’ve already looked at the course booklets, videos on Youtube, I asked the fellow and nothing, really stuck
Try to explain your answer better...
– Edu Mendonça
@Edumendonça Why don’t you try to help the person with the problem, instead of negativizing my answer? Here’s the hypocrisy!
– maicon santos
You are not, I have been denied several times for giving answers without explanation, I do not want other people to go through the same problem and another is not the purpose of stackoverflow.com to leave an answer without a logical explanation. your code can answer the question but the people who receive the answer will be left with no reason why this code should be used for it. It is the same as answering "why yes."...
– Edu Mendonça
"I don’t want other people to go through the same trouble". Then you go in there and do the same thing they did unjustly to you, to me. I was just gonna tap the comments, man, here’s the tip!
– maicon santos
Old is not me, it is the system of pt.stackoverflow.com I just analyze like any other that can do, and other I did not negatively I just signal as low quality if someone negatived neither I and nor you will know who was...
– Edu Mendonça
@Edumendonça in this I will be forced to agree with Maicon Santos. Do with the colleague what you do not like to be done with you does not make much sense.
– Letícia dos Santos
Guys I just told him to explain the answer better and not only leave a code there as answer I his answer appeared in the analysis queue and I commented I did not vote negative I just commented as all other people do with me... when I leave a code loose... without reply...
– Edu Mendonça
When you have enough points to do analysis of the questions and answers you will understand....
– Edu Mendonça