+ 1
Need hint on where my code is going wrong (Parking fee task, Kotlin)
This code passes 3 test cases but fails 3 (all hidden ones) and I can’t figure out why. I’ve manually tested many numbers in Kotlin playground and they all work. If anyone can hint what is causing the issue, I’d appreciate it! fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 total = when{ hours in 0..5 -> hours.toDouble() hours in 6..23 -> (hours.toDouble()-5)*0.5+5 else -> (hours.toDouble()-24)*0.5+15 } println(total) }
3 Respuestas
+ 8
The logic in your statements works for „up to a value“ only. Did you think, what hapen if the input value is much biger?
+ 4
It is mentioned
- for ***each*** 24 hours, there is a flat fee of $15.
Your code only works till input is 47 hrs
+ 3
Ah, thank you both! Completely forgot that multiple days exist *facepalm*