#Lua - Cars Assembly Exercise

14 messages · Page 1 of 1 (latest)

warped forum
#
local cars = {}

function cars.calculate_working_cars_per_hour(cars_per_hour, success_rate)
    return cars_per_hour * (success_rate/100)
end

function cars.calculate_working_cars_per_minute(cars_per_hour, success_rate)
    return cars.calculate_working_cars_per_hour // 60
end

function cars.calculate_cost(number_of_cars)
    if number_of_cars >= 10 then
        local group = number_of_cars // 10
        local regular = number_of_cars - (group*10)
        return (group * 95.000) + (regular * 10.000)
    else
        return number_of_cars * 10.000
    end
end

return cars
plain ridgeBOT
warped forum
#

it gives me 2 errors

#

CODE RUN
assert.are.equal(0.0, cars_assemble.calculate_working_cars_per_hour(0, 100))
assert.are.equal(221.0, cars_assemble.calculate_working_cars_per_hour(221, 100))
assert.are.equal(340.8, cars_assemble.calculate_working_cars_per_hour(426, 80))
assert.are.equal(1398.92, cars_assemble.calculate_working_cars_per_hour(6824, 20.5))
assert.are.equal(0.0, cars_assemble.calculate_working_cars_per_hour(8000, 0))
TEST FAILURE
Expected objects to be equal.
Passed in:
(number) 0
Expected:
(number) 340.80000000000001137

#

update: fixed the third function error, i put a dot on 95.000 and 10.000 when i should've not, my bad.

#

still cant understand the first, since its such a straight forward task but idk i might be wrong

warped forum
#

dont understand why lol

#

but it works now

shy quail
#

Because floats are approximate

#

And I'm guessing 80 / 100 isn't giving what you expect it to give

warped forum
#

oh okay

#

thanks

shy quail
#

You're welcome