+ 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) }

10th May 2023, 2:45 PM
Micka Kovac
3 Antworten
+ 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?
10th May 2023, 4:05 PM
JaScript
JaScript - avatar
+ 4
It is mentioned - for ***each*** 24 hours, there is a flat fee of $15. Your code only works till input is 47 hrs
10th May 2023, 4:00 PM
Atul
Atul - avatar
+ 3
Ah, thank you both! Completely forgot that multiple days exist *facepalm*
10th May 2023, 4:12 PM
Micka Kovac