Https://www.aaonline.io/alpha-curriculum/3.0/how-to-complete-projects

I have a questions on the coding to nt_remainder_without_modulo doesn’t use the % operator!

Write a method that returns the decimal remainder of dividing two integers.

HINT: Use dec_remainder_of_two_floats as a helper method,

but don’t forget to pass the proper type of argument

def dec_remainder_of_two_integers(i_dividend, i_divisor)
i_dividend.to_f%i_divisor.to_f/i_divisor
end
Why is the above correct and the below wrong?
def dec_remainder_of_two_integers(i_dividend, i_divisor)
i_dividend%i_divisor/i_divisor.to_f
end

Failures:

  1. methods.rb int_remainder_without_modulo doesn’t use the % operator
    Failure/Error: (i_dividend%i_divisor)/(i_divisor.to_f)

    (Double “Integer”).%(2)
    expected: 0 times with any arguments
    received: 1 time with arguments: (2)

    ./lib/methods.rb:97:in `dec_remainder_of_two_integers’

    ./lib/methods.rb:109:in `int_remainder_without_modulo’

    ./spec/methods_spec.rb:144:in `block (3 levels) in <top (required)>’

Can you tell me what your terminal outputs when you type in ls and when you type in pwd?

problem solved
disregard

Do you mind describing how you solved the problem? Perhaps others who run into the same issue benefit from it. :slight_smile:

The reason why the first code failed is because i_dividended and i_divisor are both intergers, and therefore i_dividended%i_divisor will exclude the decimal remaining of the quotient, but in the solution, it used i_dividended.to_f%i_divisor.to_f so the quotient will be a float

1 Like