Need hint on where my code is going wrong (Parking fee task, Kotlin) | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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
Shino
Shino - avatar
+ 3
Ah, thank you both! Completely forgot that multiple days exist *facepalm*
10th May 2023, 4:12 PM
Micka Kovac